#!/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

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

if len(sys.argv) > 1:
    import argparse
    from freeseer import settings
    from freeseer.framework.database import QtDBConnector
    from freeseer.framework.presentation import Presentation

    db = QtDBConnector(settings.configdir)

    parser = argparse.ArgumentParser(description='Freeseer TalkEditor Utility')
    parser.add_argument("action", choices=['add-talk', 'remove-talk', 'clear-database'])
    parser.add_argument("-t", "--title", type=unicode, help="Title")
    parser.add_argument("-s", "--speaker", type=unicode, help="Speaker")
    parser.add_argument("-r", "--room", type=unicode, help="Room")
    parser.add_argument("-e", "--event", type=unicode, help="Event")
    parser.add_argument("-i", "--talk-id", type=int, help="Talk ID")
    args = parser.parse_args()
    
    if args.action == "add-talk":
        presentation = Presentation(args.title,
                                    speaker=args.speaker,
                                    room=args.room,
                                    event=args.event)
        db.insert_presentation(presentation)

    elif args.action == "remove-talk":
        db.delete_presentation(args.talk_id)

    elif args.action == "clear-database":
        db.clear_database()

    else:
        # Invalid
        print("Invalid option.")


else:
    """Launch GUI if no parameters are passed"""
    from PyQt4.QtGui import QApplication
    from freeseer.frontend.talkeditor.talkeditor import TalkEditorApp

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