#! /usr/bin/env python
# -.- coding: utf-8 -.-

# Copyright (c) 2011-2012 Collabora, Ltd.
#
# Gnome Clocks 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 2 of the License, or (at your
# option) any later version.
#
# Gnome Clocks 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 Gnome Clocks; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# Author: Seif Lotfy <seif.lotfy@collabora.co.uk>

import os
import signal
import sys

# Detect if we are running from the source dir
if os.path.exists("gnome-clocks.doap"):
    ENV_PATHS = {
        "GNOME_CLOCKS_DATA_PATH": "data/",
        "GNOME_CLOCKS_IMAGE_PATH": "data/",
        "GNOME_CLOCKS_LOCALE_PATH": "locale/",
    }
else:
    ENV_PATHS = {
        "GNOME_CLOCKS_DATA_PATH": "/usr/share/gnome-clocks/",
        "GNOME_CLOCKS_IMAGE_PATH": "/usr/share/gnome-clocks/",
        "GNOME_CLOCKS_LOCALE_PATH": "/usr/share/locale/",
    }

for var, path in ENV_PATHS.iteritems():
    os.environ.setdefault(var, path)

# Setup i18n support
import locale
import gettext

from gnomeclocks.utils import Dirs

locale_domain = "gnome-clocks"
locale.setlocale(locale.LC_ALL, '')
gettext.bindtextdomain(locale_domain, Dirs.get_locale_dir())
gettext.textdomain(locale_domain)
gettext.install(locale_domain, Dirs.get_locale_dir())

from gnomeclocks.app import ClocksApplication

if __name__ == "__main__":
    app = ClocksApplication()
    # FIXME: Get rid of the following line which has the only purpose of
    # working around Ctrl+C not exiting Gtk applications from bug 622084.
    # https://bugzilla.gnome.org/show_bug.cgi?id=622084
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    exit_status = app.run(sys.argv)
    sys.exit(exit_status)
