Ejemplo n.º 1
0
func (u *User) SetBackgroundFile(dbusMsg dbus.DMessage, bg string) (bool, error) {
	pid := dbusMsg.GetSenderPID()
	err := u.accessAuthentication(pid, true, "SetBackgroundFile")
	if err != nil {
		return false, err
	}

	if bg == u.BackgroundFile {
		return true, nil
	}

	if !graphic.IsSupportedImage(bg) {
		reason := fmt.Sprintf("This background '%s' not a image", bg)
		logger.Debug(reason)
		triggerSigErr(pid, "SetBackgroundFile", reason)
		return false, err
	}

	go func() {
		src := u.BackgroundFile
		u.setPropString(&u.BackgroundFile, "BackgroundFile", bg)
		err = u.writeUserConfig()
		if err != nil {
			logger.Warning("Write user config failed:", err)
			triggerSigErr(pid, "SetBackgroundFile", err.Error())
			u.setPropString(&u.BackgroundFile, "BackgroundFile", src)
			return
		}
	}()

	return true, nil
}
Ejemplo n.º 2
0
func (bg *Background) IsValueValid(value string) bool {
	filename := dutils.DecodeURI(value)
	if dutils.IsFileExist(filename) &&
		graphic.IsSupportedImage(filename) {
		return true
	}

	return false
}
Ejemplo n.º 3
0
func (u *User) SetIconFile(dbusMsg dbus.DMessage, icon string) (bool, error) {
	pid := dbusMsg.GetSenderPID()
	err := u.accessAuthentication(pid, true, "SetIconFile")
	if err != nil {
		return false, err
	}

	if u.IconFile == icon {
		return true, nil
	}

	if !graphic.IsSupportedImage(icon) {
		reason := fmt.Sprintf("This icon '%s' not a image", icon)
		logger.Debug(reason)
		triggerSigErr(pid, "SetIconFile", reason)
		return false, err
	}

	go func() {
		target, added, err := u.addIconFile(icon)
		if err != nil {
			logger.Warning("Set icon failed:", err)
			triggerSigErr(pid, "SetIconFile", err.Error())
			return
		}

		src := u.IconFile
		u.setPropString(&u.IconFile, "IconFile", target)
		err = u.writeUserConfig()
		if err != nil {
			logger.Warning("Write user config failed:", err)
			triggerSigErr(pid, "SetIconFile", err.Error())
			u.setPropString(&u.IconFile, "IconFile", src)
			return
		}
		u.addHistoryIcon(src)
		if added {
			u.setPropStrv(&u.IconList, "IconList", u.getAllIcons())
		}
	}()

	return true, nil
}