'Create a directory entry for the model.
This ensures that directories are always listed before files.'

def create_dir_entry(self, dirname):

    entries = dirname.split(u'/')
    curdir = []
    parent = self.invisibleRootItem()
    curdir_append = curdir.append
    self_add_directory = self.add_directory
    dir_entries = self.dir_entries
    for entry in entries:
        curdir_append(entry)
        path = u'/'.join(curdir)
        try:
            parent = dir_entries[path]
        except KeyError:
            grandparent = parent
            parent = self_add_directory(grandparent, path)
            dir_entries[path] = parent
    return parent
