ecasa: add search functionality
[enigma2-plugins.git] / dreamirc / src / e2account.py
1 # -*- Python -*-
2 #
3 # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
4 # See LICENSE for details. 
5
6 #
7 import string
8 import ircsupport
9 import e2chat, dreamIRCTools, dreamIRCSetup
10
11
12 class AccountManager:
13         """I am responsible for managing a user's accounts.
14
15         That is, remembering what accounts are available, their settings,
16         adding and removal of accounts, etc.
17
18         @ivar accounts: A collection of available accounts.
19         @type accounts: mapping of strings to L{Account<interfaces.IAccount>}s.
20         """
21         def __init__(self,session):
22                 self.chatui = e2chat.ChatUI()
23                 self.config = dreamIRCSetup.dreamIRCConfig()
24                 self.accounts = self.config.load()
25                 self.pipe = dreamIRCTools.MessagePipe()
26
27         def startConnect(self):
28                 if self.accounts==False:
29                         self.pipe.debug("You have defined no valid accounts.")
30                 else:
31                         for acct in self.accounts:
32                                 acct.logOn(self.chatui)
33
34         def getSnapShot(self):
35                 """A snapshot of all the accounts and their status.
36
37                 @returns: A list of tuples, each of the form
38                         (string:accountName, boolean:isOnline,
39                         boolean:autoLogin, string:gatewayType)
40                 """
41                 data = []
42                 for account in self.accounts:
43                         data.append((account.accountName, account.isOnline(),account.autoLogin, account.gatewayType))
44                 return data
45
46         def isEmpty(self):
47                 return len(self.accounts) == 0
48
49         def getConnectionInfo(self):
50                 if self.accounts==False:
51                         self.pipe.debug("You have defined no valid accounts.")
52                         return [0]
53                 else:
54                         connectioninfo = []
55                         for account in self.accounts:
56                                 connectioninfo.append(account.isOnline())
57                         return connectioninfo
58
59         def addAccount(self, account):
60                 self.accounts[account.accountName] = account
61
62         def delAccount(self, accountName):
63                 del self.accounts[accountName]
64
65         def connect(self, accountName, chatui):
66                 """
67                 @returntype: Deferred L{interfaces.IClient}
68                 """
69                 self.pipe.debug("connecting to : %s" % accountName)
70                 return self.accounts[accountName].logOn(chatui)
71
72         def quit(self):
73                 pass
74