#!/usr/bin/python
# -*- coding: utf-8 -*-

# freeseer - vga/presentation capture software
#
#  Copyright (C) 2011-2013  Free and Open Source Software Learning Centre
#  http://fosslc.org
#
#  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/>.

# For support, questions, suggestions or any other inquiries, visit:
# http://wiki.github.com/Freeseer/freeseer/

import signal
import sys

###
### Program Start
###
signal.signal(signal.SIGINT, signal.SIG_DFL)

if len(sys.argv) > 1:
    """If arguments are passed, act as a commandline"""
    import argparse
    import gobject
    
    parser = argparse.ArgumentParser(description='Freeseer Recording Utility')
    parser.add_argument("-t", "--talk", type=int, help="Talk ID of the talk you would like to record")
    parser.add_argument("-f", "--filename", type=unicode, help="Record to filename")
    parser.add_argument("-p", "--profile", type=unicode, help="Use profile")
    parser.add_argument("-s", "--show-talks", help="Shows all talks", action="store_true")
    args = parser.parse_args()


    # Must declare after argparse otherwise GStreamer will take over the cli help
    from freeseer.frontend.record.RecordingController import RecordingController

    if args.profile:
        app = RecordingController(cli=True, profile=args.profile)
    else:
        app = RecordingController(cli=True)

    if args.talk:
        if app.record_talk_id(args.talk): sys.exit(gobject.MainLoop().run())
    elif args.filename:
        if app.record_filename(args.filename): sys.exit(gobject.MainLoop().run())
    elif args.show_talks:
        app.print_talks()
    

else:
    """Launch the GUI if no arguments are passed"""
    from PyQt4.QtGui import QApplication
    from freeseer.frontend.record.record import RecordApp

    app = QApplication(sys.argv)
    main = RecordApp()
    main.show()
    sys.exit(app.exec_())
