예제 #1
0
    def on_location_changed(self, monitor, gfile, other_gfile, event):
        """
            Updates the library on changes of the location
        """

        if event == Gio.FileMonitorEvent.CHANGES_DONE_HINT:
            self.__process_change_queue(gfile)
        elif event == Gio.FileMonitorEvent.CREATED or \
                event == Gio.FileMonitorEvent.CHANGED:

            # Enqueue tracks retrieval
            if gfile not in self.__queue:
                self.__queue[gfile] = True

                # File monitor only emits the DONE_HINT when using inotify,
                # and only on single files. Give it some time, but don't
                # lose the change notification
                GLib.timeout_add(500, self.__process_change_queue, gfile)

            # Set up new monitor if directory
            fileinfo = gfile.query_info('standard::type', Gio.FileQueryInfoFlags.NONE, None)

            if fileinfo.get_file_type() == Gio.FileType.DIRECTORY and \
               gfile not in self.__monitors:

                for directory in common.walk_directories(gfile):
                    monitor = directory.monitor_directory(Gio.FileMonitorFlags.NONE, None)
                    monitor.connect('changed', self.on_location_changed)
                    self.__monitors[directory] = monitor

                    self.emit('location-added', directory)

        elif event == Gio.FileMonitorEvent.DELETED:
            removed_tracks = []

            track = trax.Track(gfile.get_uri())

            if track in self.__library.collection:
                # Deleted file was a regular track
                removed_tracks += [track]
            else:
                # Deleted file was most likely a directory
                for track in self.__library.collection:
                    track_gfile = Gio.File.new_for_uri(track.get_loc_for_io())

                    if track_gfile.has_prefix(gfile):
                        removed_tracks += [track]

            self.__library.collection.remove_tracks(removed_tracks)

            # Remove obsolete monitors
            removed_directories = [d for d in self.__monitors
                                   if d == gfile or d.has_prefix(gfile)]

            for directory in removed_directories:
                self.__monitors[directory].cancel()
                del self.__monitors[directory]

                self.emit('location-removed', directory)
예제 #2
0
    def on_location_changed(self, monitor, gfile, other_gfile, event):
        """
            Updates the library on changes of the location
        """
        
        if event == Gio.FileMonitorEvent.CHANGES_DONE_HINT:
            self.__process_change_queue(gfile)
        elif event == Gio.FileMonitorEvent.CREATED or \
             event == Gio.FileMonitorEvent.CHANGED:
            
            # Enqueue tracks retrieval
            if gfile not in self.__queue:
                self.__queue[gfile] = True
            
                # File monitor only emits the DONE_HINT when using inotify,
                # and only on single files. Give it some time, but don't 
                # lose the change notification
                GLib.timeout_add(500, self.__process_change_queue, gfile)
            
            # Set up new monitor if directory
            fileinfo = gfile.query_info('standard::type', Gio.FileQueryInfoFlags.NONE, None)

            if fileinfo.get_file_type() == Gio.FileType.DIRECTORY and \
               gfile not in self.__monitors:
                
                for directory in common.walk_directories(gfile):
                    monitor = directory.monitor_directory(Gio.FileMonitorFlags.NONE, None)
                    monitor.connect('changed', self.on_location_changed)
                    self.__monitors[directory] = monitor

                    self.emit('location-added', directory)

        elif event == Gio.FileMonitorEvent.DELETED:
            removed_tracks = []

            track = trax.Track(gfile.get_uri())

            if track in self.__library.collection:
                # Deleted file was a regular track
                removed_tracks += [track]
            else:
                # Deleted file was most likely a directory
                for track in self.__library.collection:
                    track_gfile = Gio.File.new_for_uri(track.get_loc_for_io())

                    if track_gfile.has_prefix(gfile):
                        removed_tracks += [track]

            self.__library.collection.remove_tracks(removed_tracks)

            # Remove obsolete monitors
            removed_directories = [d for d in self.__monitors \
                if d == gfile or d.has_prefix(gfile)]

            for directory in removed_directories:
                self.__monitors[directory].cancel()
                del self.__monitors[directory]
                
                self.emit('location-removed', directory)
예제 #3
0
    def __update_monitors(self):
        """
            Sets up or removes library monitors
        """
        with self.__lock:
            if self.props.monitored:
                logger.debug('Setting up library monitors')

                for directory in common.walk_directories(self.__root):
                    monitor = directory.monitor_directory()
                    monitor.connect('changed', self.on_location_changed)
                    self.__monitors[directory] = monitor

                    self.emit('location-added', directory)
            else:
                logger.debug('Removing library monitors')

                for directory, monitor in self.__monitors.iteritems():
                    monitor.cancel()

                    self.emit('location-removed', directory)

                self.__monitors = {}
예제 #4
0
    def __update_monitors(self):
        """
            Sets up or removes library monitors
        """
        with self.__lock:
            if self.props.monitored:
                logger.debug('Setting up library monitors')

                for directory in common.walk_directories(self.__root):
                    monitor = directory.monitor_directory(Gio.FileMonitorFlags.NONE, None)
                    monitor.connect('changed', self.on_location_changed)
                    self.__monitors[directory] = monitor

                    self.emit('location-added', directory)
            else:
                logger.debug('Removing library monitors')

                for directory, monitor in self.__monitors.iteritems():
                    monitor.cancel()

                    self.emit('location-removed', directory)

                self.__monitors = {}