#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# @author: Florian Dorn <florian.dorn@gmail.com>
# @package: agenda
# @license: GNU GPLv2
#
# 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.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import sys
import copy
try:
	import pygtk
	import pango
	import gtk
	import gtk.glade
	
	v = gtk.pygtk_version
	if( not (v[0] >1 and v[1] > 9)):
		print "Could not import GTK version (> 2.10)"
		sys.exit(1)		
	
except:
	print "Could not import GTK version (> 2.10)"
	sys.exit(1)

import dbus
import dbus.service
import dbus.glib

try:
	import re
	import os
	import time
	import string
	import gobject
	from gettext import gettext as _
	from configobj import ConfigObj
except:
	print "python ConfigObj is not installed" 
	sys.exit(1)

import logging
LOGGER = logging.getLogger(__name__)


from optparse import OptionParser
	
import agenda
from agenda.appointment import *
import agenda.static
from agenda.ui.Agenda import Agenda

__author__ = 'florian.dorn@gmail.com (Florian Dorn)'


# Parse commandline options
usage = "agenda [-p] [-v]"
parser = OptionParser(usage=usage,version="agenda %s" % agenda.static.APP_VERSION)
parser.add_option("-p", "--preferences", dest="pref", default=False, action="store_true", help="Display Preferences")
parser.add_option("-u", "--update", dest="update", default=False, action="store_true", help="Update Calendars")
parser.set_defaults(preferences=False)


(options, args) = parser.parse_args()

	


#if options.debug:
#	logging.getLogger().setLevel(logging.DEBUG)

#holds the appointments
database = None

dbus.mainloop.glib.DBusGMainLoop (set_as_default=True)
bus = dbus.SessionBus ()
request = bus.request_name ("org.domain.GnomeAgenda", dbus.bus.NAME_FLAG_DO_NOT_QUEUE)
if request != dbus.bus.REQUEST_NAME_REPLY_EXISTS:
	init_plugin_system()
	database = Appointments()
	agenda = Agenda (database,bus, '/', "org.domain.GnomeAgenda")
else:
	object = bus.get_object ("org.domain.GnomeAgenda", "/")
	#agenda only has the proxy methods
	agenda = dbus.Interface (object, "org.domain.GnomeAgenda")
	
agenda.start(options.__dict__)
if agenda.is_running ():
	gtk.gdk.notify_startup_complete ()


