#! /usr/libexec/platform-python
# -*- coding: utf-8 -*-
# fonts-tweak-tool
# Copyright (c) 2011-2012 Jian Ni <jni@redhat.com>
# Copyright (c) 2012-2015 Red Hat, Inc.
#
# Authors:
#   Akira TAGOH  <tagoh@redhat.com>
#
# This library is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, either
# version 3 of the License, or (at your option) any later version.
#
# This library 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 sys
import gi
from fontstweak.main import FontsTweakToolApp
gi.require_version('FontsTweak', '0')
from gi.repository import FontsTweak

import gettext
import locale
import os
import signal
from fontstweak.fontstweak import FontsTweakConst
gi.require_version('Easyfc', '0.14')
gi.require_version('Gio', '2.0')
gi.require_version('GLib', '2.0')
from gi.repository import Easyfc
from gi.repository import Gio
from gi.repository import GLib

gi.require_version('Gtk', '3.0')

if __name__ == '__main__':
    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error as e:
        os.environ['LC_ALL'] = 'C'
        locale.setlocale(locale.LC_ALL, '')

    gettext.install(FontsTweakConst.GETTEXT_PACKAGE, FontsTweakConst.LOCALEDIR, codeset=locale.nl_langinfo(locale.CODESET), names=('gettext', 'ngettext'))
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    Gio.Resource._register(FontsTweak.get_resource())

    Easyfc.init()
    config = Easyfc.Config()
    config.set_name("fontstweak")
    try:
        # This method is available on libeasyfc >= 0.8
        config.set_migration(True)
    except AttributeError as e:
        pass

    try:
        config.load()
    except GLib.GError as e:
        if e.domain != 'ezfc-error-quark' or e.code != 7:
            raise

    app = FontsTweakToolApp(config)
    sys.exit(app.run(None))
