# Path: vocto/debug.py
# def gst_log_messages(level):
# 
#     gstLog = logging.getLogger('Gst')
# 
#     def log( level, msg ):
#         if level == Gst.DebugLevel.WARNING:
#             gstLog.warning(msg)
#         if level == Gst.DebugLevel.FIXME:
#             gstLog.warning(msg)
#         elif level == Gst.DebugLevel.ERROR:
#             gstLog.error(msg)
#         elif level == Gst.DebugLevel.INFO:
#             gstLog.info(msg)
#         elif level == Gst.DebugLevel.DEBUG:
#             gstLog.debug(msg)
# 
#     def logFunction(category, level, file, function, line, object, message, *user_data):
#         global gst_log_messages_lastmessage, gst_log_messages_lastlevel, gst_log_messages_repeat
# 
#         msg = message.get()
#         if gst_log_messages_lastmessage != msg:
#             if gst_log_messages_repeat > 2:
#                 log(gst_log_messages_lastlevel,"%s [REPEATING %d TIMES]" % (gst_log_messages_lastmessage, gst_log_messages_repeat))
# 
#             gst_log_messages_lastmessage = msg
#             gst_log_messages_repeat = 0
#             gst_log_messages_lastlevel = level
#             log(level,"%s: %s (in function %s() in file %s:%d)" % (object.name if object else "", msg, function, file, line))
#         else:
#             gst_log_messages_repeat += 1
# 
# 
#     Gst.debug_remove_log_function(None)
#     Gst.debug_add_log_function(logFunction,None)
#     Gst.debug_set_default_threshold(level)
#     Gst.debug_set_active(True)


import gi
import signal
import logging
import sys
import os
    import lib.connection as Connection
    import lib.connection as Connection
    import lib.clock as ClockManager
from gi.repository import Gtk, Gdk, Gst, GstVideo
from vocto.debug import gst_log_messages
        from lib.args import Args
        from lib.ui import Ui
    from lib import args
    from lib.args import Args
    from lib.loghandler import LogHandler
    from lib import config
    from lib.config import Config
        self.log.info('Setting UI visible')
        self.ui.show()

        try:
            self.log.info('Running.')
            Gtk.main()
            self.log.info('Connection lost. Exiting.')
        except KeyboardInterrupt:
            self.log.info('Terminated via Ctrl-C')

    def quit(self):
        self.log.info('Quitting.')
        Gtk.main_quit()


# run mainclass
def main():
    # parse command-line args
    args.parse()

    docolor = (Args.color == 'always') \
        or (Args.color == 'auto' and sys.stderr.isatty())

    handler = LogHandler(docolor, Args.timestamp)
    logging.root.addHandler(handler)

    levels = { 3 : logging.DEBUG, 2 : logging.INFO, 1 : logging.WARNING, 0 : logging.ERROR }
    logging.root.setLevel(levels[Args.verbose])

    gst_levels = { 3 : Gst.DebugLevel.DEBUG, 2 : Gst.DebugLevel.INFO, 1 : Gst.DebugLevel.WARNING, 0 : Gst.DebugLevel.ERROR }

# Path: vocto/debug.py
# def gst_log_messages(level):
# 
#     gstLog = logging.getLogger('Gst')
# 
#     def log( level, msg ):
#         if level == Gst.DebugLevel.WARNING:
#             gstLog.warning(msg)
#         if level == Gst.DebugLevel.FIXME:
#             gstLog.warning(msg)
#         elif level == Gst.DebugLevel.ERROR:
#             gstLog.error(msg)
#         elif level == Gst.DebugLevel.INFO:
#             gstLog.info(msg)
#         elif level == Gst.DebugLevel.DEBUG:
#             gstLog.debug(msg)
# 
#     def logFunction(category, level, file, function, line, object, message, *user_data):
#         global gst_log_messages_lastmessage, gst_log_messages_lastlevel, gst_log_messages_repeat
# 
#         msg = message.get()
#         if gst_log_messages_lastmessage != msg:
#             if gst_log_messages_repeat > 2:
#                 log(gst_log_messages_lastlevel,"%s [REPEATING %d TIMES]" % (gst_log_messages_lastmessage, gst_log_messages_repeat))
# 
#             gst_log_messages_lastmessage = msg
#             gst_log_messages_repeat = 0
#             gst_log_messages_lastlevel = level
#             log(level,"%s: %s (in function %s() in file %s:%d)" % (object.name if object else "", msg, function, file, line))
#         else:
#             gst_log_messages_repeat += 1
# 
# 
#     Gst.debug_remove_log_function(None)
#     Gst.debug_add_log_function(logFunction,None)
#     Gst.debug_set_default_threshold(level)
#     Gst.debug_set_active(True)


# Path: voctogui/voctogui.py
import gi
import signal
import logging
import sys
import os
    import lib.connection as Connection
    import lib.connection as Connection
    import lib.clock as ClockManager
from gi.repository import Gtk, Gdk, Gst, GstVideo
from vocto.debug import gst_log_messages
        from lib.args import Args
        from lib.ui import Ui
    from lib import args
    from lib.args import Args
    from lib.loghandler import LogHandler
    from lib import config
    from lib.config import Config

        self.log.info('Setting UI visible')
        self.ui.show()

        try:
            self.log.info('Running.')
            Gtk.main()
            self.log.info('Connection lost. Exiting.')
        except KeyboardInterrupt:
            self.log.info('Terminated via Ctrl-C')

    def quit(self):
        self.log.info('Quitting.')
        Gtk.main_quit()


# run mainclass
def main():
    # parse command-line args
    args.parse()

    docolor = (Args.color == 'always') \
        or (Args.color == 'auto' and sys.stderr.isatty())

    handler = LogHandler(docolor, Args.timestamp)
    logging.root.addHandler(handler)

    levels = { 3 : logging.DEBUG, 2 : logging.INFO, 1 : logging.WARNING, 0 : logging.ERROR }
    logging.root.setLevel(levels[Args.verbose])

    gst_levels = { 3 : Gst.DebugLevel.DEBUG, 2 : Gst.DebugLevel.INFO, 1 : Gst.DebugLevel.WARNING, 0 : Gst.DebugLevel.ERROR }

    gst_log_messages(gst_levels[Args.gstreamer_log])