def _reload_shortcuts(self): recent_documents_dir = get_special_folder_path(shellcon.CSIDL_RECENT) """ shortcuts = chain( get_shortcuts_from_dir(desktop_dir), get_shortcuts_from_dir(quick_launch_dir, startmenu_ignored_links), get_shortcuts_from_dir(start_menu_dir, startmenu_ignored_links), get_shortcuts_from_dir(common_start_menu_dir, startmenu_ignored_links), get_gameexplorer_entries(), iter(get_control_panel_applets()), get_special_folders(), get_shortcuts_from_dir(LEARN_AS_DIR) ) """ self.shortcut_dict = ShortcutsDict() @timed("Loaded recent documents shortcuts") @synchronized() @initialize_pythoncom def reload_recent_shortcuts(path=None): _ = path self.shortcut_dict.update( get_shortcuts_from_dir(recent_documents_dir, max_depth=0, category=self._create_category)) reload_recent_shortcuts() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME)(reload_recent_shortcuts), ((recent_documents_dir, False), )) return self.shortcut_dict
def register_monitor_callback(callback_func): dirwatcher.register_monitor_callback(callback_func, ((BOOKMARKS_DIR, False), ))
def register_monitor_callback(callback_func): dirwatcher.register_monitor_callback(callback_func, ( ("/usr/share/applications", False), ("/usr/local/share/applications", False), (os.path.expanduser("~/.local/share/applications"), False), ))
def _reload_shortcuts(self, shortcuts_dict): try: shortcuts_dict.update(load_cached_shortcuts()) logging.info("Loaded shortcuts from cache") except Exception as e: logging.error(e) desktop_dir = get_special_folder_path(shellcon.CSIDL_DESKTOPDIRECTORY) common_desktop_dir = get_special_folder_path( shellcon.CSIDL_COMMON_DESKTOPDIRECTORY) quick_launch_dir = pathjoin( get_special_folder_path(shellcon.CSIDL_APPDATA), "Microsoft", "Internet Explorer", "Quick Launch") user_pinned_dir = pathjoin( get_special_folder_path(shellcon.CSIDL_APPDATA), "Microsoft", "Internet Explorer", "Quick Launch", "User Pinned") start_menu_dir = get_special_folder_path(shellcon.CSIDL_STARTMENU) common_start_menu_dir = get_special_folder_path( shellcon.CSIDL_COMMON_STARTMENU) virtualmachines_dir = pathjoin( get_special_folder_path(shellcon.CSIDL_PROFILE), "Virtual Machines") recent_documents_dir = get_special_folder_path(shellcon.CSIDL_RECENT) """ shortcuts = chain( get_shortcuts_from_dir(desktop_dir), get_shortcuts_from_dir(quick_launch_dir, startmenu_ignored_links), get_shortcuts_from_dir(start_menu_dir, startmenu_ignored_links), get_shortcuts_from_dir(common_start_menu_dir, startmenu_ignored_links), get_gameexplorer_entries(), iter(get_control_panel_applets()), get_special_folders(), get_shortcuts_from_dir(LEARN_AS_DIR) ) """ """ import cProfile cProfile.runctx( 'list(get_shortcuts_from_dir(desktop_dir))', globals(), locals()) """ @timed_execution("Loaded common-desktop shortcuts", mute_on_false=True) @synchronized() def reload_commom_desktop_shortcuts(path=None, all_calls_params=[]): # Get unique list of changed paths # ('all_calls_params' arg is provided by the @debounce decorator) changed_paths = set( chain.from_iterable(args for (args, kwargs) in all_calls_params)) # Act only on file changes and exclude certain files if changed_paths and not any( not isdir(p) and basename(p) not in ('desktop.ini', ) for p in changed_paths): print "Skipping changed path(s): ", changed_paths return False #with timed_execution("Loaded common-desktop shortcuts"): shortcuts_dict.update_by_dir( common_desktop_dir, dict((s.name, s) for s in get_shortcuts_from_dir( common_desktop_dir, max_depth=0, collect_dirs=True #,category="desktop" if self.use_categories else None ))) return True reload_commom_desktop_shortcuts() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME)( reload_commom_desktop_shortcuts), ((common_desktop_dir, False), ), ) @timed_execution("Loaded user-desktop shortcuts", mute_on_false=True) @synchronized() @initialize_pythoncom def reload_user_desktop_shortcuts(path=None, all_calls_params=[]): # Get unique list of changed paths # ('all_calls_params' arg is provided by the @debounce decorator) changed_paths = set( chain.from_iterable(args for (args, kwargs) in all_calls_params)) # Act only on file changes and exclude certain files if changed_paths and not any( not isdir(p) and basename(p) not in ('desktop.ini', ) for p in changed_paths): print "Skipping changed path(s): ", changed_paths return False shortcuts_dict.update_by_dir( desktop_dir, dict((s.name, s) for s in get_shortcuts_from_dir( desktop_dir, max_depth=0, collect_dirs=True #,category="desktop" if self.use_categories else None ))) return True reload_user_desktop_shortcuts() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME)( reload_user_desktop_shortcuts), ((desktop_dir, False), ), ) @timed_execution("Loaded quick-launch shortcuts", mute_on_false=True) @synchronized() @initialize_pythoncom def reload_quick_launch_shortcuts(path=None, all_calls_params=[]): # Get unique list of changed paths # ('all_calls_params' arg is provided by the @debounce decorator) changed_paths = set( chain.from_iterable(args for (args, kwargs) in all_calls_params)) # Act only on file changes and exclude certain files if changed_paths and not any( isfile(p) #and basename(p) not in ('desktop.ini',) and splitext(p)[1] == '.lnk' for p in changed_paths): print "Skipping changed path(s): ", changed_paths return False shortcuts_dict.update_by_dir( quick_launch_dir, dict((s.name, s) for s in get_shortcuts_from_dir( quick_launch_dir, startmenu_ignored_links, # max_depth=2 will handle also "User Pinned/[TaskBar|StartMenu]" subdirs max_depth=2, collect_dirs=True #,category="quicklaunch" if self.use_categories else None ))) return True reload_quick_launch_shortcuts() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME)( reload_quick_launch_shortcuts), ((quick_launch_dir, True), ), ) pathsplit = os.path.split _, start_menu_name = pathsplit(start_menu_dir) _, common_start_menu_name = pathsplit(common_start_menu_dir) def get_startmenu_category(name, type, target, filename): # Get the last sub-menu name _, category = pathsplit(pathsplit(filename)[0]) # We are on the top of the start-menu if category in (start_menu_name, common_start_menu_name): return "startmenu" # We are in some of the sub-menus, return the sub-menu name category = unicodedata.normalize('NFKD', unicode(category)).encode( 'ascii', 'ignore').lower() return "startmenu %s" % category @timed_execution("Loaded user-start-menu shortcuts", mute_on_false=True) @synchronized() @initialize_pythoncom def reload_user_start_menu_shortcuts(path=None, all_calls_params=[]): # Get unique list of changed paths # ('all_calls_params' arg is provided by the @debounce decorator) changed_paths = set( chain.from_iterable(args for (args, kwargs) in all_calls_params)) # Act only on file changes and exclude certain files if changed_paths and not any( not isdir(p) and basename(p) not in ('desktop.ini', ) for p in changed_paths): print "Skipping changed path(s): ", changed_paths return False shortcuts_dict.update_by_dir( start_menu_dir, dict((s.name, s) for s in get_shortcuts_from_dir( start_menu_dir, startmenu_ignored_links, category=get_startmenu_category if self. use_categories else None))) return True reload_user_start_menu_shortcuts() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME)( reload_user_start_menu_shortcuts), ((start_menu_dir, False), ), ) @timed_execution("Loaded common-start-menu shortcuts", mute_on_false=True) @synchronized() @initialize_pythoncom def reload_common_start_menu_shortcuts(path=None, all_calls_params=[]): # Get unique list of changed paths # ('all_calls_params' arg is provided by the @debounce decorator) changed_paths = set( chain.from_iterable(args for (args, kwargs) in all_calls_params)) # Act only on file changes and exclude certain files if changed_paths and not any( not isdir(p) and basename(p) not in ('desktop.ini', ) for p in changed_paths): print "Skipping changed path(s): ", changed_paths return False shortcuts_dict.update_by_dir( common_start_menu_dir, dict((s.name, s) for s in get_shortcuts_from_dir( common_start_menu_dir, startmenu_ignored_links, category=get_startmenu_category if self. use_categories else None))) return True reload_common_start_menu_shortcuts() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME)( reload_common_start_menu_shortcuts), ((common_start_menu_dir, False), ), ) @timed_execution("Loaded Virtual PC machines") @synchronized() @initialize_pythoncom def reload_virtual_pc_machines(path=None): shortcuts_dict.update_by_dir( virtualmachines_dir, dict((s.name, s) for s in get_shortcuts_from_dir(virtualmachines_dir, category="virtual machine" if self. use_categories else None))) reload_virtual_pc_machines() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME)( reload_virtual_pc_machines), ((virtualmachines_dir, False), )) with timed_execution("Loaded control-panel applets"): shortcuts_dict.update( dict((s.name, s) for s in get_control_panel_applets(self.use_categories))) with timed_execution("Loaded special folders shortcuts"): shortcuts_dict.update( dict((s.name, s) for s in get_special_folders(self.use_categories))) if os.path.isdir(GAMEEXPLORER_DIR): @timed_execution("Loaded gameexplorer entries") @synchronized() @initialize_pythoncom def reload_gameexplorer_shortcuts(path=None): shortcuts_dict.update( dict((s.name, s) for s in get_gameexplorer_entries( self.use_categories))) reload_gameexplorer_shortcuts() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME) (reload_gameexplorer_shortcuts), ((GAMEEXPLORER_DIR, False), )) @timed_execution("Loaded Enso learn-as shortcuts", mute_on_false=True) @synchronized() @initialize_pythoncom def reload_enso_learned_shortcuts(path=None, all_calls_params=[]): # Get unique list of changed paths # ('all_calls_params' arg is provided by the @debounce decorator) changed_paths = set( chain.from_iterable(args for (args, kwargs) in all_calls_params)) # Act only on file changes and exclude certain files if changed_paths and not any( not isdir(p) and basename(p) not in ('desktop.ini', ) for p in changed_paths): print "Skipping changed path(s): ", changed_paths return False shortcuts_dict.update_by_dir( LEARN_AS_DIR, dict((s.name, s) for s in get_shortcuts_from_dir( LEARN_AS_DIR, max_depth=0, #,category="learned" if self.use_categories else None flags=SHORTCUT_FLAG_LEARNED))) return True reload_enso_learned_shortcuts() dirwatcher.register_monitor_callback( debounce(SHORTCUTS_REFRESH_DEBOUNCE_TIME)( reload_enso_learned_shortcuts), ((LEARN_AS_DIR, False), ), ) try: save_shortcuts_cache(shortcuts_dict) logging.info("Updated shortcuts cache") except Exception as e: logging.error(e)
def register_monitor_callback(callback_func): dirwatcher.register_monitor_callback(callback_func, ((LEARN_AS_DIR, False), ))
def register_monitor_callback_launchpanel(callback_func): dirwatcher.register_monitor_callback(callback_func, ((LAUNCH_PANEL_DIR, False), ))
def register_monitor_callback_desktop(callback_func): dirwatcher.register_monitor_callback(callback_func, ((DESKTOP_DIR, False), ))