#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2011 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, 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 warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
"""The main script for the Ubuntu One Installer."""

import apt
import os

from gi.repository import Gtk, GLib


def is_installed(package):
    """Check if things are installed already."""
    try:
        cache = apt.Cache()
        return package in cache and cache[package].is_installed
    except SystemError:
        return os.path.exists('/usr/bin/ubuntuone-control-panel-gtk')

    
if __name__ == "__main__":
    if is_installed('ubuntuone-control-panel-gtk'):
        GLib.spawn_command_line_async('ubuntuone-control-panel-gtk')
    else:
        from ubuntuone.installer.gui import Window
        dialog = Window()
        dialog.run()
        Gtk.main()
