#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#       kazam
#
#       Copyright 2012 David Klasinc <bigwhale@lubica.net>
#       Copyright 2010 Andrew <andrew@karmic-desktop>
#
#       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, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

from argparse import ArgumentParser
import logging
import os
import sys

from gi.repository import Gtk

if __name__ == "__main__":

    log =  logging.getLogger()
    log.name = "Kazam"
    handler = logging.StreamHandler()
    formatter = logging.Formatter('%(levelname)s %(name)-10s - %(message)s')
    handler.setFormatter(formatter)
    log.addHandler(handler)

    log.info("Logger intialized.")

    if os.path.exists("../data"):
        log.info("Running locally, AppIndicator icons might be missing.")
        datadir = "../data"
        sys.path.insert(0, "..")
    else:
        # A bit more flexible setting of datadir, it works
        # when base install path is not /usr
        curpath = os.path.abspath(__file__)
        datadir = curpath.split('bin/')[0] + "share/kazam/"

    from kazam.version import *
    version = "%(prog)s {0} '{1}'".format(VERSION, CODENAME)
    parser = ArgumentParser(description = "Screen recording program.")

    parser.add_argument("-d", "--debug",
                        action = "store_true",
                        help = "enable debug mode",
                        default = False)

    parser.add_argument("-v", "--version",
                        action = "version",
                        version = version)

    args = parser.parse_args()
    if args.debug:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)

    from kazam.app import KazamApp

    log.debug("Starting ...")
    appWindow = KazamApp(datadir, args.debug)
    appWindow.show_all()
    Gtk.main()
    log.debug("Finishing ...")
