dreamIRC initial check-in
[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.startConnect()     
26
27 #        if self.accounts==False:
28 #            print "You have defined no accounts."
29 #        else:
30 #            for acct in self.accounts:
31 #                               acct.logOn(self.chatui)
32
33         def startConnect(self):
34                 if self.accounts==False:
35                         print "You have defined no accounts."
36                 else:
37                         for acct in self.accounts:
38                                 acct.logOn(self.chatui)
39
40         def getSnapShot(self):
41                 """A snapshot of all the accounts and their status.
42
43                 @returns: A list of tuples, each of the form
44                         (string:accountName, boolean:isOnline,
45                         boolean:autoLogin, string:gatewayType)
46                 """
47                 data = []
48 #               for account in self.accounts.values():
49                 for account in self.accounts:
50                         data.append((account.accountName, account.isOnline(),account.autoLogin, account.gatewayType))
51                 return data
52
53         def isEmpty(self):
54                 return len(self.accounts) == 0
55
56         def getConnectionInfo(self):
57                 connectioninfo = []
58                 for account in self.accounts:
59                         connectioninfo.append(account.isOnline())
60                 return connectioninfo
61
62         def addAccount(self, account):
63                 self.accounts[account.accountName] = account
64
65         def delAccount(self, accountName):
66                 del self.accounts[accountName]
67
68         def connect(self, accountName, chatui):
69                 """
70                 @returntype: Deferred L{interfaces.IClient}
71                 """
72                 print "----1---- %s" % accountName
73                 return self.accounts[accountName].logOn(chatui)
74
75         def quit(self):
76                 pass
77                 #for account in self.accounts.values():
78                 #    account.logOff()  - not yet implemented