#!/usr/local/bin/python2.5
# -*- coding:utf-8 -*-

# -----------------------------------------------------------------------------
# Getting Things Gnome! - A personal organizer for the GNOME desktop
# Copyright (c) 2008,2009 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/>.
# -----------------------------------------------------------------------------

"""
This script create a new task and launch the editor to display it. GTG should be running
"""



import dbus

def get_task() :
    #We will connect on the session bus
    bus = dbus.SessionBus()
    liste = bus.list_names()
    busname = None
    busgps = None
    #We take the list of all buses actually available
    for i in liste :
        if i.startswith("org.GTG") :
            busname = i
    if busname :
        remote_object = bus.get_object(busname,"/org/GTG")
        timi = dbus.Interface(remote_object,dbus_interface="org.GTG")
        #Calling the method
        timi.open_new_task()
    else:
        print "GTG not found on DBus. Are you sure GTG is started?"
        
        
if __name__ == '__main__':
    get_task()
