#!/usr/bin/python

# gfeeds
#
# Copyright (C) 2019 Gabriele Musco <emaildigabry@gmail.com>
#
# 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 os
import sys
import signal
import gettext
import locale

sys.path.insert(1, '/usr/lib/python3.11/site-packages')

# compositing causes issues for webkit in some website with nvidia drivers
os.environ['WEBKIT_DISABLE_COMPOSITING_MODE'] = '1'

VERSION = '0.16.2'
pkgdatadir = '/usr/share/gfeeds'
localedir = '/usr/share/locale'
builddir = os.environ.get('MESON_BUILD_ROOT')
if builddir:
    pkgdatadir = os.path.join(builddir, 'data')
    os.environ['GSETTINGS_SCHEMA_DIR'] = pkgdatadir
    sys.dont_write_bytecode = True
    sys.path.insert(1, os.environ['MESON_SOURCE_ROOT'])

signal.signal(signal.SIGINT, signal.SIG_DFL)

# Why both locale and gettext?
# gettext works for the python part
# but not for the glade/xml files
# they need locale
# don't ask me, it's effin weird
# I copied this from uberwriter
try:
    locale.bindtextdomain('gfeeds', localedir)
    locale.textdomain('gfeeds')
except AttributeError as e:
    # Python built without gettext support doesn't have bindtextdomain()
    # and textdomain()
    print("Couldn't bind the gettext translation domain. Some translations"
    " won't work. Error: \n{}".format(e))
gettext.textdomain('gfeeds')
gettext.bindtextdomain('gfeeds', localedir)

if __name__ == '__main__':
    import gi

    gi.require_version('Gtk', '3.0')
    gi.require_version('WebKit2', '4.0')
    gi.require_version('Gdk', '3.0')
    gi.require_version('Handy', '1')


    from gi.repository import Gio
    resource = Gio.Resource.load(os.path.join(pkgdatadir, 'org.gabmus.gfeeds.gresource'))
    resource._register()

    from gfeeds import __main__
    __main__.main()
