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

# Copyright (C) 2004-2010 Johan Svedberg <johan@svedberg.com>

# This file is part of OnTV.

# OnTV 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 2 of the License, or
# (at your option) any later version.

# OnTV 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 OnTV; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

import sys
import os.path

import pygtk
pygtk.require("2.0")
import gtk
import gnome
import gnomeapplet

import ontv.gui
from ontv.applet import OnTVApplet
from ontv import NAME, VERSION, LOCALE_DIR

PYTHON_DIR = "/usr/local/lib/python2.6/dist-packages"

# Try to determine if we run from source or install and fix path accordingly
def _check(path):
    return os.path.exists(path) and os.path.isdir(path) and \
           os.path.isfile(path + "/AUTHORS")

name = os.path.join(os.path.dirname(__file__), "..")
if _check(name):
    sys.path.insert(0, os.path.abspath(name))
elif PYTHON_DIR not in sys.path:
    sys.path.insert(0, os.path.abspath(PYTHON_DIR))

def applet_factory(applet, iid=None, configure=False, debug=False):
    ontvapplet = OnTVApplet(applet, configure, debug)
    ontvapplet.run()
    return True

if __name__ == "__main__":

    gnome.init(NAME, VERSION)
    gtk.gdk.threads_init()
    gtk.window_set_default_icon_list(*ontv.gui.get_icon_list([16,22,24,32,48]))

    configure = False
    debug = False
    gnomeapplet.bonobo_factory("OAFIID:GNOME_OnTVApplet_Factory",
                               gnomeapplet.Applet.__gtype__, NAME, VERSION,
                               applet_factory, (configure, debug, ))


# vim: set sw=4 et sts=4 tw=79 fo+=l:
