#!/usr/local/bin/python3.8
# -----------------------------------------------------------------------------
# Getting Things GNOME! - a personal organizer for the GNOME desktop
# Copyright (c) 2008-2015 - Lionel Dricot & Bertrand Rousseau
#
# 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/>.
#
#==============================================================================
#
# Getting things GNOME!: a gtd-inspired organizer for GNOME
#
# @author : B. Rousseau, L. Dricot
# @date   : November 2008
#
#   main.py contains the configuration and data structures loader
#   taskbrowser.py contains the main GTK interface for the tasklist
#   task.py contains the implementation of a task and a project
#   taskeditor contains the GTK interface for task editing
#       (it's the window you see when writing a task)
#   backends/xml_backend.py is the way to store tasks and project in XML
#
#   tid stand for "Task ID"
#   pid stand for "Project ID"
#   uid stand for "Universal ID" which is generally the tuple [pid,tid]
#
#   Each id are *strings*
#   tid are the form "X@Y" where Y is the pid.
#   For example : 21@2 is the 21st task of the 2nd project
#   This way, we are sure that a tid is unique accross multiple projects
#
#==============================================================================

"""This is the top-level exec script for running GTG"""

#=== IMPORT ===================================================================
import sys
import argparse

import gi
gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0')

from GTG.core import info
from GTG.gtk.application import Application


def parse_args():
    """Parse arguments from the command line."""

    parser = argparse.ArgumentParser()

    parser.add_argument('-v', '--version', help='Show program version',
                        action="store_true")

    parser.add_argument('-d', '--debug', help='Enable debug output',
                        action='store_true')

    parser.add_argument('-t', '--title',
                        help='Use special title for windows\' title')

    parser.add_argument('task_uri', default='', nargs='*', type=str,
                        help='Open a specific task via URI')

    return parser.parse_args()


if __name__ == "__main__":
    try:
        args = parse_args()

        if args.version:
            print("GTG (Getting Things GNOME!)", info.VERSION)
            print()
            print("For more information:", info.URL)
            sys.exit(0)

        if args.title is not None:
            info.NAME = args.title

        application = Application(args.debug)
        application.uri_list = args.task_uri
        application.run()

    except KeyboardInterrupt:
        sys.exit(1)
