def do_setclient(self): """Change default email client""" from client import Client client = Client(self.wf) app_path = self.args.query log.debug('Setting new client to : {}'.format(app_path)) if app_path == 'DEFAULT': # Reset to system default del self.wf.settings['default_app'] msg = 'Email client set to System Default' log.info(msg) self.notify(msg) run_alfred('{} '.format(CONFIG_KEYWORD)) return if not os.path.exists(app_path): msg = "Application doesn't exist : {}".format(app_path) self.notify(msg) raise ValueError(msg) client.default_app = app_path msg = 'Email client set to : {}'.format(client.default_app['name']) log.info(msg) self.notify(msg) run_alfred('{} '.format(CONFIG_KEYWORD))
def do_reload(self): """Force update of contacts cache""" log.debug('Forcing cache update ...') from contacts import Contacts from client import Client Contacts().update(force=True) Client(self.wf).update(force=True) self.notify('Refreshing contacts and app caches…') run_alfred('{} '.format(CONFIG_KEYWORD)) return 0
def toggle_help_text(self): """Turn additional usage notes in subtitles on/off""" if self.wf.settings.get('show_help', True): self.wf.settings['show_help'] = False msg = 'Turned additional help text off' else: self.wf.settings['show_help'] = True msg = 'Turned additional help text on' log.debug(msg) self.notify(msg) # Re-open settings run_alfred('{} '.format(CONFIG_KEYWORD))
def toggle_notify_cache_updates(self): """Turn cache update notifications on/off""" if self.wf.settings.get('cache_notify_updates', True): self.wf.settings['cache_notify_updates'] = False msg = 'Turned cache update notifications off' else: self.wf.settings['cache_notify_updates'] = True msg = 'Turned cache update notifications on' log.debug(msg) self.notify(msg) # Re-open settings run_alfred('{} '.format(CONFIG_KEYWORD))
def toggle_format(self): """Change format between name+email and email-only""" if self.wf.settings.get('use_name', True): self.wf.settings['use_name'] = False msg = 'Changed format to Email Only' else: self.wf.settings['use_name'] = True msg = 'Changed format to Name & Email' log.debug(msg) self.notify(msg) # Re-open settings run_alfred('{} '.format(CONFIG_KEYWORD))
def do_config(self): """Show configuration""" log.debug('Showing settings') query = self.args.query log.debug('query : {}'.format(query)) # Go back # -------------------------------------------------------------- if query.endswith(SEPARATOR): # User deleted trailing space run_alfred('{} '.format(CONFIG_KEYWORD)) return # Subquery # -------------------------------------------------------------- # Parse subqueries and dispatch to appropriate method # A subquery is `keyword + <SEPARATOR> + <space>` # `query` will be the rest of the original `query` after # the first `<SEPARATOR>` if SEPARATOR in query: parts = [s.strip() for s in query.split(SEPARATOR) if s.strip()] log.debug('parts : {}'.format(parts)) if parts: action = parts[0] if len(parts) > 1: query = parts[1] else: query = None # `Client` is the only subquery at the moment if action == 'Client': return self.choose_client(query) else: self.wf.add_item('Unknown setting : {}'.format(action), 'Try a different query', icon=ICON_WARNING) self.wf.send_feedback() return # Display root configuration options # -------------------------------------------------------------- items = self.get_config_items() # Filter items if a query was given if query: items = self.wf.filter(query, items, lambda d: d['title'], min_score=50) # Show error message if not items: subtitle = 'Try a different query' if not self.wf.settings.get('show_help', True): subtitle = None self.wf.add_item('Nothing matches', subtitle, icon=ICON_WARNING) # Send feedback for item in items: if not self.wf.settings.get('show_help', True): item['subtitle'] = None self.wf.add_item(**item) self.wf.send_feedback()