// NewListJob creates a new list job for dbus.
func NewListJob(path string, flags operations.ListJobFlag) *ListJob {
	job := &ListJob{
		dbusInfo: genDBusInfo("ListJob", &_ListJobCount),
		op:       operations.NewListDirJob(path, flags),
	}
	return job
}
// GenMenu generates json format menu content used in DeepinMenu for AppGroup.
func (item *AppGroup) GenMenu() (*Menu, error) {
	item.menu = NewMenu()
	return item.menu.AppendItem(NewMenuItem(Tr("_Open"), func(uint32) {
		ops := make([]int32, len(item.uris))
		for i := range item.uris {
			ops[i] = OpOpen
		}
		item.app.emitRequestOpen(item.uris, ops)
	}, true)).AddSeparator().AppendItem(NewMenuItem(Tr("_Rename"), func(uint32) {
		item.emitRequestRename()
	}, !item.multiple)).AddSeparator().AppendItem(NewMenuItem(Tr("_Ungroup"), func(uint32) {
		for _, uri := range item.uris {
			files := []string{}

			listJob := operations.NewListDirJob(uri, operations.ListJobFlagIncludeHidden)
			listJob.ListenProperty(func(p operations.ListProperty) {
				files = append(files, p.URI)
			})
			listJob.Execute()
			if err := listJob.GetError(); err != nil {
				Log.Warningf("list appgroup %s failed: %s\n", uri, err)
				continue
			}

			moveJob := operations.NewMoveJob(files, GetDesktopDir(), "", 0, nil)
			moveJob.Execute()
			if err := moveJob.GetError(); err != nil {
				Log.Warningf("dismiss appgroup %s failed: %s\n", uri, err)
			}
		}
	}, true)).AddSeparator().AppendItem(NewMenuItem(Tr("_Delete"), func(uint32) {
		item.emitRequestDelete()
	}, true)), nil
}
func (app *Application) listDir(dir string, flag operations.ListJobFlag) (map[string]ItemInfo, error) {
	infos := map[string]ItemInfo{}

	job := operations.NewListDirJob(dir, flag)

	job.ListenProperty(func(p operations.ListProperty) {
		if !shouldNotShow(p) {
			infos[p.URI] = app.getItemInfo(p)
		}
	})

	job.Execute()

	if job.HasError() {
		return map[string]ItemInfo{}, job.GetError()
	}

	return infos, nil
}