Example #1
0
	def __init__(self, reg):
		super(Network, self).__init__(name="PyTideNetwork", speed=.1)
		self.registry = reg
		self.connection = None
		self._status = "No connection"
		self.wavelets = []
		self.contacts = []
		# start loading configs now. Let access block later if necessary
		self.savedlogins = Config(namespace="savedlogins")
		self.savedlogins.setAutoTimer(3)
		self.loginWindow = self.registry.newLoginWindow(self.connect, self.savedlogins)
		self.start()
Example #2
0
class Network(threads.LoopingThread):
	'''The Network object is a thread, and it communicates between the connection plugin
	(also a thread) and the rest of the program. It holds the "official" version of every
	wavelet in its own memory.
	
	It handles the application of operations, notifying the appropriate objects in reg
	when stuff happens, and the management of connection plugins. '''

	def __init__(self, reg):
		super(Network, self).__init__(name="PyTideNetwork", speed=.1)
		self.registry = reg
		self.connection = None
		self._status = "No connection"
		self.wavelets = []
		self.contacts = []
		# start loading configs now. Let access block later if necessary
		self.savedlogins = Config(namespace="savedlogins")
		self.savedlogins.setAutoTimer(3)
		self.loginWindow = self.registry.newLoginWindow(self.connect, self.savedlogins)
		self.start()

	def process(self):
		if self.is_connected():
			pass
			#self.connection.sync()

	def query(self, wlcallback, query, startpage=0, errcallback=None):
		''' External function - send a query to the plugin '''
		def callback(results):
			self._query(results, wlcallback)
		def err(e):
			self.plugin_error(e, errcallback)
		self.connection.query(query, startpage, callback, err)

	def _query(self, results, wlcallback):
		''' Expects a models.SearchResults from the plugin '''
		self.registry.setIcon('active')
		wlcallback(results)

	def connect(self, username, password):
		print "Network connecting to %s" % username
		domain = username.split('@')[1]
		print 'About to get connection from plugins.'
		connection = plugins.get_plugin(domain)
		print 'Got connection from plugins.'
		if connection:
			try:
				self.status("Connecting to %s" % domain)
				self.connection = connect(connection,
                                                          username=username,
                                                          password=password,
                                                          domain=domain)
				self.status("Connected")
				self.loginWindow.hide()
				self.registry.newWaveList()
				self.saveLogin(username, password,)
				return True
			except NetworkTools.ConnectionFailure, e:
				self.status("Connection Failed - Your internet may be down or your login data incorrect")
				return False
		else: