Example #1
0
 def update(self):
     shortcuts_dict = recent_command_impl.get_shortcuts()
     if self.postfixes_updated_on >= shortcuts_dict.updated_on:
         return
     with timed_execution("Setting postfixes for 'recent' command."):
         self.setPostfixes(shortcuts_dict.keys())
     self.postfixes_updated_on = shortcuts_dict.updated_on
Example #2
0
 def update(self):
     shortcuts_dict = open_command_impl.get_shortcuts()
     if self.postfixes_updated_on >= shortcuts_dict.updated_on:
         return
     with timed_execution("Setting postfixes for 'unlearn open' command."):
         self.setPostfixes(s[0] for s in shortcuts_dict.iteritems()
                           if s[1].flags & shortcuts.SHORTCUT_FLAG_LEARNED)
     self.postfixes_updated_on = shortcuts_dict.updated_on
 def get_shortcuts(self, force_reload=False):
     """ Return ShortcutsDict of all collected Shortcut objects """
     if force_reload or self.shortcut_dict is None:
         with timed_execution("Reloaded shortcuts dict"):
             if self.shortcut_dict is None:
                 self.shortcut_dict = shortcuts.ShortcutsDict()
             self._reload_shortcuts(self.shortcut_dict)
     return self.shortcut_dict
Example #4
0
 def update(self):
     shortcuts_dict = open_command_impl.get_shortcuts()
     if self.postfixes_updated_on >= shortcuts_dict.updated_on:
         return
     with timed_execution("Setting postfixes for 'open with' command."):
         self.setPostfixes([
             s.name for s in shortcuts_dict.values()
             if s.type == shortcuts.SHORTCUT_TYPE_EXECUTABLE
         ])
     self.postfixes_updated_on = shortcuts_dict.updated_on
 def reloader_thread(self):
     with timed_execution("Refreshed \"open\" command shortcuts dict"):
         self._reload_shortcuts(self.shortcut_dict)
         """
Example #6
0
    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)