...
 
Commits (7)
......@@ -2,7 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
image: debian:stretch
image: debian:buster
before_script:
- apt update && apt install --no-install-recommends -y gir1.2-gtk-3.0 python3-gi python3-pip python3-setuptools
......
......@@ -5,7 +5,7 @@
project(
'briar-gtk',
version: '0.1.0',
meson_version: '>= 0.40.0',
meson_version: '>= 0.50.0',
)
i18n = import('i18n')
......
......@@ -15,24 +15,43 @@ import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio
pkgdatadir = '@pkgdatadir@'
localedir = '@localedir@'
PACKAGE_DATA_DIR = '@PACKAGE_DATA_DIR@'
LOCALE_DIR = '@LOCALE_DIR@'
sys.path.insert(1, pkgdatadir)
signal.signal(signal.SIGINT, signal.SIG_DFL)
def add_package_to_sys_path():
sys.path.insert(1, PACKAGE_DATA_DIR)
if __name__ == '__main__':
locale.bindtextdomain('briar-gtk', localedir)
def handle_sigint_default_way():
signal.signal(signal.SIGINT, signal.SIG_DFL)
def prepare_locale():
locale.bindtextdomain('briar-gtk', LOCALE_DIR)
locale.textdomain('briar-gtk')
gettext.bindtextdomain('briar-gtk', localedir)
def prepare_gettext():
gettext.bindtextdomain('briar-gtk', LOCALE_DIR)
gettext.textdomain('briar-gtk')
import gi
def prepare_localization():
prepare_locale()
prepare_gettext()
from gi.repository import Gio
resource = Gio.Resource.load(os.path.join(pkgdatadir, 'briar-gtk.gresource'))
def prepare_resource():
resource = Gio.Resource.load(os.path.join(PACKAGE_DATA_DIR, 'briar-gtk.gresource'))
resource._register()
def prepare():
add_package_to_sys_path()
handle_sigint_default_way()
prepare_localization()
prepare_resource()
def start_application():
from briar.gtk.application import Application
sys.exit(Application("@VERSION@").run(sys.argv))
sys.exit(Application().run(sys.argv))
if __name__ == '__main__':
prepare()
start_application()
......@@ -10,45 +10,56 @@ from gi.repository import Gdk, Gio, GLib, Gtk
from briar.api.api import Api
from briar.gtk.define import APPLICATION_ID, APPLICATION_NAME
from briar.gtk.define import BRIAR_HEADLESS_JAR
from briar.gtk.window import Window
class Application(Gtk.Application):
def __init__(self, version):
GLib.set_application_name("Briar")
GLib.set_prgname("Briar")
super().__init__(application_id='app.briar.gtk')
self.window = None
self._set_version(version)
def __init__(self):
Application._set_application_name()
super().__init__(application_id=APPLICATION_ID)
# pylint: disable=arguments-differ
def do_startup(self):
Gtk.Application.do_startup(self)
Application._setup_styling()
self._setup_api()
# pylint: disable=arguments-differ
def do_activate(self):
self._setup_window()
# pylint: disable=arguments-differ
def quit(self):
self.api.stop()
self.window.hide()
Gio.Application.quit(self)
@staticmethod
def _set_application_name():
GLib.set_application_name(APPLICATION_NAME)
GLib.set_prgname(APPLICATION_NAME)
@staticmethod
def _setup_styling():
css_provider_file = Gio.File.new_for_uri(
"resource:///app/briar/gtk/ui/application.css")
css_provider = Gtk.CssProvider()
css_provider.load_from_file(css_provider_file)
screen = Gdk.Screen.get_default()
style_context = Gtk.StyleContext()
style_context.add_provider_for_screen(screen, css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
self.api = Api('/app/briar/briar-headless.jar')
def _setup_api(self):
self.api = Api(BRIAR_HEADLESS_JAR)
# pylint: disable=arguments-differ
def do_activate(self):
if self.window is None:
# pylint: disable=access-member-before-definition
def _setup_window(self):
if not hasattr(self, "window") or self.window is None:
self.window = Window()
self.window.show()
self.window.present()
# pylint: disable=arguments-differ
def quit(self):
self.api.stop()
self.window.hide()
Gio.Application.quit(self)
def _set_version(self, version):
self._version = version
......@@ -2,7 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
from gi.repository import GLib, GObject, Gtk
from gi.repository import GLib
from briar.gtk.container import Container
from briar.gtk.define import App
......@@ -13,7 +13,6 @@ class StartupContainer(Container):
def __init__(self):
super().__init__()
self._api = App().api
StartupContainer._register_signals()
self._setup_view()
# pylint: disable=unused-argument
......@@ -29,18 +28,13 @@ class StartupContainer(Container):
"password_confirm_entry").get_text()
if password != password_confirm:
raise Exception("Passwords do not match")
self._api.register((self.username, password), self._startup_finished)
self._api.register((self.username, password),
StartupContainer._startup_completed)
# pylint: disable=unused-argument
def on_login_pressed(self, button):
password = self.builder.get_object("password_entry").get_text()
self._api.login(password, self._startup_finished)
@staticmethod
def _register_signals():
GObject.signal_new("briar_startup_completed", Gtk.Overlay,
GObject.SignalFlags.RUN_LAST, GObject.TYPE_BOOLEAN,
(GObject.TYPE_STRING,))
self._api.login(password, StartupContainer._startup_completed)
def _setup_view(self):
self.set_hexpand(True)
......@@ -53,8 +47,9 @@ class StartupContainer(Container):
self.add(self.builder.get_object("login"))
self.builder.connect_signals(self)
def _startup_finished(self, succeeded):
@staticmethod
def _startup_completed(succeeded):
if succeeded:
GLib.idle_add(self.emit, "briar_startup_completed", (succeeded,))
GLib.idle_add(App().window.on_startup_completed)
return
print("Startup failed")
......@@ -8,4 +8,8 @@
from gi.repository import Gio
APPLICATION_ID = "app.briar.gtk"
APPLICATION_NAME = "Briar"
BRIAR_HEADLESS_JAR = "/app/briar/briar-headless.jar"
App = Gio.Application.get_default # pylint: disable=invalid-name
# Copyright (c) 2019 Nico Alt
# Copyright (c) 2014-2018 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
# Copyright (c) 2017 Bilal Elmoussaoui <bil.elmoussaoui@gmail.com>
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
#
# Initial version based on GNOME Lollypop
# https://gitlab.gnome.org/World/lollypop/blob/1.0.2/lollypop/logger.py
import logging
import sys
from briar.gtk.define import App
class Logger:
FORMAT = "[%(levelname)-s] %(asctime)s %(message)s"
DATE = "%Y-%m-%d %H:%M:%S"
__log = None
APP = "app.briar.gtk"
@staticmethod
def get_default():
if Logger.__log is None:
logger = logging.getLogger(Logger.APP)
handler = logging.StreamHandler(sys.stdout)
formater = logging.Formatter(Logger.FORMAT, Logger.DATE)
handler.setFormatter(formater)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
Logger.__log = logging.getLogger(Logger.APP)
return Logger.__log
@staticmethod
def warning(msg, *args):
Logger.get_default().warning(msg, *args)
@staticmethod
def debug(msg, *args):
if App().debug:
Logger.get_default().debug(msg, *args)
@staticmethod
def info(msg, *args):
Logger.get_default().info(msg, *args)
@staticmethod
def error(msg, *args):
Logger.get_default().error(msg, *args)
......@@ -7,15 +7,16 @@ from gi.repository import Gtk
from briar.gtk.containers.chat import ChatContainer
from briar.gtk.containers.main import MainContainer
from briar.gtk.containers.startup import StartupContainer
from briar.gtk.define import App
from briar.gtk.define import App, APPLICATION_ID, APPLICATION_NAME
from briar.gtk.toolbar import Toolbar
class Window(Gtk.ApplicationWindow):
DEFAULT_WINDOW_SIZE = (600, 400)
def __init__(self):
Gtk.ApplicationWindow.__init__(self, application=App(), title="Briar",
icon_name="app.briar.gtk")
self._initialize_gtk_application_window()
self._setup_content()
@property
......@@ -26,18 +27,27 @@ class Window(Gtk.ApplicationWindow):
def toolbar(self):
return self._toolbar
def _initialize_gtk_application_window(self):
Gtk.ApplicationWindow.__init__(self, application=App(),
title=APPLICATION_NAME,
icon_name=APPLICATION_ID)
def _setup_content(self):
self._setup_size((600, 400)) # TODO: do properly (constants, save)
self._setup_size(self.DEFAULT_WINDOW_SIZE)
self._setup_toolbar()
self._setup_grid()
self._setup_startup_container()
def _setup_size(self, size):
if len(size) == 2 and\
isinstance(size[0], int) and\
isinstance(size[1], int):
if Window._size_is_valid(size):
self.resize(size[0], size[1])
@staticmethod
def _size_is_valid(size):
return len(size) == 2 and\
isinstance(size[0], int) and\
isinstance(size[1], int)
def _setup_toolbar(self):
self._toolbar = Toolbar()
self._toolbar.show()
......@@ -46,20 +56,15 @@ class Window(Gtk.ApplicationWindow):
def _setup_grid(self):
self._grid = Gtk.Grid()
self._grid.set_orientation(Gtk.Orientation.HORIZONTAL)
self._grid.show()
self.add(self._grid)
def _setup_startup_container(self):
self._container = StartupContainer()
self._container.show()
self._container.connect("briar_startup_completed",
self._on_startup_completed)
self._grid.add(self._container)
# TODO: remove unused arguments
# pylint: disable=unused-argument
def _on_startup_completed(self, inst, obj):
def on_startup_completed(self):
self._grid.destroy()
self._setup_grid()
self._setup_main_container()
......@@ -80,6 +85,7 @@ class Window(Gtk.ApplicationWindow):
self._grid.add(self._container)
self._toolbar.show_back_button(True, self._back_to_main)
# pylint: disable=unused-argument
def _back_to_main(self, widget):
self._grid.destroy()
self._setup_grid()
......
......@@ -2,16 +2,16 @@
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
moduledir = join_paths(pkgdatadir, 'briar')
PACKAGE_DATA_DIR = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
MODULE_DIR = join_paths(PACKAGE_DATA_DIR, 'briar')
python3 = import('python3')
conf = configuration_data()
conf.set('PYTHON', python3.find_python().path())
conf.set('VERSION', meson.project_version())
conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir)
conf.set('LOCALE_DIR', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('PACKAGE_DATA_DIR', PACKAGE_DATA_DIR)
configure_file(
input: 'briar-gtk.in',
......@@ -21,5 +21,5 @@ configure_file(
install_dir: get_option('bindir')
)
install_subdir('briar/api', install_dir: moduledir)
install_subdir('briar/gtk', install_dir: moduledir)
install_subdir('briar/api', install_dir: MODULE_DIR)
install_subdir('briar/gtk', install_dir: MODULE_DIR)