#!/usr/bin/env python3

# beat.in
#
# Copyright 2020 thankjura
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import gi
import os
import sys
import signal
import gettext
import locale

pkgdatadir = '/usr/share/beat'
localedir = '/usr/share/locale'
application_id = 'ru.slie.beat'

sys.path.insert(1, pkgdatadir)
signal.signal(signal.SIGINT, signal.SIG_DFL)

gi.require_version("Gtk", "3.0")
gi.require_version('Gst', '1.0')
gi.require_version('Gio', '2.0')
gi.require_version('AppIndicator3', '0.1')


def set_resources():
    from gi.repository import Gio
    resource = Gio.Resource.load(os.path.join(pkgdatadir, 'beat.gresource'))
    Gio.resources_register(resource)
    #resource._register()

def set_internationalization():
    try:
        locale.bindtextdomain('beat', localedir)
        locale.textdomain('beat')
    except AttributeError as e:
        print(
            "Could not bind the gettext translation domain. Some"
            " translations will not work. Error:\n{}".format(e))

    gettext.bindtextdomain('beat', localedir)
    gettext.textdomain('beat')

def run_application():
    from beat.application import Application

    app = Application(application_id)
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    return app.run(sys.argv)


if __name__ == '__main__':
    set_internationalization()
    set_resources()
    sys.exit(run_application())
