enable debug mode.. when enabled also server communication is logged to /var/log...
[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
26         def startConnect(self):
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 getSnapShot(self):
34                 """A snapshot of all the accounts and their status.
35
36                 @returns: A list of tuples, each of the form
37                         (string:accountName, boolean:isOnline,
38                         boolean:autoLogin, string:gatewayType)
39                 """
40                 data = []
41                 for account in self.accounts:
42                         data.append((account.accountName, account.isOnline(),account.autoLogin, account.gatewayType))
43                 return data
44
45         def isEmpty(self):
46                 return len(self.accounts) == 0
47
48         def getConnectionInfo(self):
49                 connectioninfo = []
50                 for account in self.accounts:
51                         connectioninfo.append(account.isOnline())
52                 return connectioninfo
53
54         def addAccount(self, account):
55                 self.accounts[account.accountName] = account
56
57         def delAccount(self, accountName):
58                 del self.accounts[accountName]
59
60         def connect(self, accountName, chatui):
61                 """
62                 @returntype: Deferred L{interfaces.IClient}
63                 """
64                 print "----1---- %s" % accountName
65                 return self.accounts[accountName].logOn(chatui)
66
67         def quit(self):
68                 pass
69                 #for account in self.accounts.values():
70                 #    account.logOff()  - not yet implemented