Example #1
0
func (bg *Background) Set(uri string) error {
	settings := NewGSettings("com.deepin.wrap.gnome.desktop.background")
	defer Unref(settings)

	value := settings.GetString(settingsKeyPictureURI)
	if isBackgroundSame(uri, value) {
		return nil
	}

	if isBackgroundInInfoList(uri, bg.infoList) {
		settings.SetString(settingsKeyPictureURI, uri)
		return nil
	}

	// cp uri to user wallpapers
	src := dutils.DecodeURI(uri)
	if !dutils.IsFileExist(src) {
		src = defaultBgFile
	}
	dir := getUserWallpaper()
	if len(dir) == 0 {
		return errUserPict
	}

	filename := path.Join(dir, path.Base(src))
	err := dutils.CopyFile(src, filename)
	if err != nil {
		return err
	}
	settings.SetString(settingsKeyPictureURI,
		dutils.EncodeURI(filename, dutils.SCHEME_FILE))

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

	return false
}
Example #3
0
func isBackgroundSame(uri1, uri2 string) bool {
	bg1 := dutils.DecodeURI(uri1)
	bg2 := dutils.DecodeURI(uri2)

	md51, ok := dutils.SumFileMd5(bg1)
	if !ok {
		return false
	}
	md52, ok := dutils.SumFileMd5(bg2)
	if !ok {
		return false
	}
	if md51 == md52 {
		return true
	}

	return false
}
Example #4
0
func (bg *Background) GetThumbnail(src string) string {
	thumb := GetThumbnail(BackgroundThumbSeed, src)
	if len(thumb) != 0 {
		return thumb
	}

	GenerateThumbnail()
	return dutils.DecodeURI(src)
}
Example #5
0
// SetBackgroundSourceFile setup the background source file, then
// generate the background to fit the screen resolution, support png
// and jpeg image format.
func (theme *Theme) SetBackgroundSourceFile(imageFile string) (ok bool, err error) {
	imageFile = utils.DecodeURI(imageFile)
	ok = graphic.IsSupportedImage(imageFile)
	if ok {
		go func() {
			theme.doSetBackgroundSourceFile(imageFile)
		}()
	}
	return
}
Example #6
0
func getBgDirList(infoList []PathInfo) []string {
	var list []string

	for _, info := range infoList {
		dir := dutils.DecodeURI(info.FilePath)
		list = append(list, dir)
	}

	return list
}
Example #7
0
func (bg *Background) Delete(uri string) error {
	for _, info := range bg.infoList {
		if info.FilePath == uri {
			if info.FileFlag == FileFlagUserOwned {
				return os.RemoveAll(dutils.DecodeURI(info.FilePath))
			}
			break
		}
	}

	return nil
}
Example #8
0
func GetThumbnail(seed, uri string) string {
	if !isThumbSeedValid(seed) {
		return ""
	}

	src := dutils.DecodeURI(uri)
	dir := path.Join(os.Getenv("HOME"), userThumbFileDir)
	md5Str, _ := dutils.SumStrMd5(seed + src)
	dest := path.Join(dir, md5Str+".png")
	if dutils.IsFileExist(dest) {
		//return dutils.EncodeURI(dest, dutils.SCHEME_FILE)
		return dest
	}

	dest = path.Join(systemThumbFileDir, md5Str+".png")
	if dutils.IsFileExist(dest) {
		//return dutils.EncodeURI(dest, dutils.SCHEME_FILE)
		return dest
	}

	return ""
}
Example #9
0
// convert uri to local path, etc "file:///the/path" -> "/the/path"
func toLocalPath(path string) (localPath string) {
	return utils.DecodeURI(path)
}