window.py 1.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
# Copyright (c) 2014-2020 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
# Copyright (c) 2020 Nico Alt
# 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.2.20/lollypop/application_actions.py

from gi.repository import Gio, GLib

from briar_gtk.containers.main import MainContainer
from briar_gtk.define import APP


# pylint: disable=too-few-public-methods
class WindowActions:

    def __init__(self):
        self._setup_actions()

    # pylint: disable=no-member
    def _setup_actions(self):
        back_to_sidebar_action = Gio.SimpleAction.new(
            "back-to-sidebar", None)
        back_to_sidebar_action.connect("activate", self._back_to_sidebar)
        APP().set_accels_for_action("win.back-to-sidebar", ["<Ctrl>w"])
        self.add_action(back_to_sidebar_action)

        open_add_contact_action = Gio.SimpleAction.new(
            "open-add-contact", None)
        open_add_contact_action.connect("activate", self._open_add_contact)
        self.add_action(open_add_contact_action)

        open_private_chat_action = Gio.SimpleAction.new(
            "open-private-chat", GLib.VariantType.new("i"))
        open_private_chat_action.connect("activate", self._open_private_chat)
        self.add_action(open_private_chat_action)

    # pylint: disable=unused-argument
    def _back_to_sidebar(self, action, parameter):
        if isinstance(self.current_container, MainContainer):
            self.current_container.show_sidebar()

    # pylint: disable=unused-argument
    def _open_add_contact(self, action, parameter):
        self.show_add_contact_container()

    # pylint: disable=unused-argument
    def _open_private_chat(self, action, contact_id):
        self.current_container.open_private_chat(contact_id.get_int32())