diff --git a/hrafn.conf b/hrafn.conf index c8e8f19..3309942 100644 --- a/hrafn.conf +++ b/hrafn.conf @@ -3,7 +3,3 @@ debug=0 entries=20 refreshtime=5 dbfile=~/.hrafn.db - -[account] -username=username -password=password diff --git a/hrafn.py b/hrafn.py index aaa6105..874ce4a 100755 --- a/hrafn.py +++ b/hrafn.py @@ -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