More work on the infrastructure for oauth... basic widgets should be in place now

This commit is contained in:
Anna 2010-05-20 17:10:12 -04:00
parent 5b4a4d760d
commit b9fb21c46e
2 changed files with 41 additions and 35 deletions

View File

@ -3,7 +3,3 @@ debug=0
entries=20
refreshtime=5
dbfile=~/.hrafn.db
[account]
username=username
password=password

View File

@ -46,14 +46,10 @@ class Hrafn():
if config.has_option('global', 'debug') and config.get('global', 'debug') == '1':
debug = True
if len(config.sections()) < 2:
print "Error: You must define at least one [account] section in " + config_file
sys.exit(1)
# Init the glade stuff here, so we don't have a race condition with
# the lists-ready signal
self.init_user_interface('./default.glade')
self.first_account_item = None
# And init the DB stuff here
db_file = os.path.expanduser(config.get('global', 'dbfile'))
@ -71,19 +67,25 @@ class Hrafn():
# Now set up the accounts and their corresponding APIs
self.accounts = {}
for token in self.db['tokens']:
api = CustomApi(token)
username = api.username
self.accounts[username] = api
self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready)
self.add_account(token)
if not self.db.has_key('active_user'):
self.db['active_user'] = self.accounts.keys()[0]
try:
self.db['active_user'] = self.accounts.keys()[0]
except KeyError:
self.db['active_user'] = None
self.username = self.db['active_user']
self.api = self.accounts[self.username]
try:
self.api = self.accounts[self.username]
except KeyError:
self.api = None
if not self.db.has_key('open_tabs'):
self.db['open_tabs'] = [(self.username + '/Home', None, False), ('@' + self.username, None, False), (self.username + '/Direct Messages', None, False)]
self.db['open_tabs'] = []
# refresh_time is in minutes... convert to seconds here
self.refresh_time *= 60
@ -121,24 +123,6 @@ class Hrafn():
self.context_id = self.status_bar.get_context_id('message')
# Add the accounts to the accounts menu
# Setup the new sub-menu
first_item = None
keys =self.accounts.keys()
keys.sort()
for name in keys:
menu_item = gtk.RadioMenuItem(first_item, label=name, use_underline=False)
menu_item.set_draw_as_radio(False)
if name == self.username:
menu_item.set_active(True)
if first_item is None:
first_item = menu_item
menu_item.connect('activate', self.on_account_changed, name)
self.accounts_menu.append(menu_item)
menu_item.show()
# Add debug options to help menu
if debug:
menu_item = gtk.MenuItem('debug: Show Threads')
@ -559,7 +543,33 @@ class Hrafn():
tokens = self.db['tokens']
tokens.append(token)
self.db['tokens'] = tokens
self.accounts['username'] = api
self.add_account(token)
def add_account(self, token):
api = CustomApi(token)
username = api.username
self.accounts[username] = api
self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready)
# Add account's menu item
menu_item = gtk.RadioMenuItem(self.first_account_item, label=username, use_underline=False)
if not self.first_account_item:
self.first_account_item = menu_item
menu_item.set_draw_as_radio(False)
if username == self.username:
menu_item.set_active(True)
if first_item is None:
first_item = menu_item
menu_item.connect('activate', self.on_account_changed, name)
self.accounts_menu.append(menu_item)
menu_item.show()
### end class Hrafn