#!/usr/bin/env python
import os
import sys
import tempfile
import threading

import common

program = None
if len(sys.argv) == 3:
    buildDir = sys.argv[1]
    srcDir = sys.argv[2]
else:
    if len(sys.argv) == 2:
        program = sys.argv[1]
        if program.endswith('.py'):
            program = program[:-3]
    buildDir = '..'
    srcDir = '.'

common.importModules(buildDir=buildDir, srcDir=srcDir)

from common import gobject, gio

gobject.threads_init()

class GIOCopyThread(threading.Thread):
    def __init__(self, uri):
        threading.Thread.__init__(self)
        self.source = gio.File(uri)
        self.dest = gio.File(tempfile.mktemp())

    def run(self):
        print "GIO START"
        self.source.copy(self.dest)
        print "GIO FINISHED: %s" % self.dest

class UI:
    
    URL = "http://files.conduit-project.org/Conduit-0.3.0-screencast-small.ogg"

    def __init__(self):
        gobject.timeout_add(300,self._tick)
        gobject.timeout_add(1500,self._gio_copy)

    def _gio_copy(self):
        t = GIOCopyThread(self.URL)
        print "STARTING THREAD"
        t.start()
        print "STARTED THREAD"
        return False

    def _tick(self):
        print "."
        return True

    def main(self):
        gobject.MainLoop().run()

if __name__ == "__main__":
    u = UI()
    u.main()
