#!/usr/bin/env python
#
# Time Drive - based on duplicity - Encrypted bandwidth efficient backup
# Requires Duplicity Version 0.6.02 released July 08, 2009
#
# Copyright 2009 Rob Oakes	<LyX-Devel@oak-tree>

import sys
from PyQt4 import QtCore
import timedrive
from timedrive.backupsettings.settings import Settings
from timedrive.background import backupjob
from timedrive.backupsettings import globals
from timedrive.utils import log

import gettext
gettext.install("time-drive")

class MainRoutine(QtCore.QObject):
	def __init__(self):
		QtCore.QObject.__init__(self)
		self.settings = Settings()
		self.settings.Mode = globals.BatchMode
		self.BackupJob = backupjob.BackupJob(self)
		QtCore.QObject.connect(self.BackupJob, QtCore.SIGNAL("finished()"), self.QuitApplication)
	
	def StartBackup(self):
		self.BackupJob.StartBackup(self.settings)
		
	def QuitApplication(self):
		log.Info(globals.APPLICATIONNAME + _(" Backup ended "))
		sys.exit()
	
def main():
	app = QtCore.QCoreApplication(sys.argv)
	app.setOrganizationName(globals.ORGANIZATIONNAME)
	app.setOrganizationDomain(globals.ORGANIZATIONDOMAIN)
	app.setApplicationName(globals.APPLICATIONNAME)

	log.setup()
	log.Info(globals.APPLICATIONNAME + _(" Backup started "))
	
	mainRoutine = MainRoutine()
	mainRoutine.StartBackup()
	sys.exit(app.exec_())
	
if __name__ == "__main__":
	main()
