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 }
func copyXDGDirConfig(home, lang string) error { src := path.Join("/etc/skel.locale", lang, "user-dirs.dirs") if !dutils.IsFileExist(src) { return fmt.Errorf("Not found this file: %s", src) } dest := path.Join(home, ".config", "user-dirs.dirs") return dutils.CopyFile(src, dest) }
func (m *Manager) modifyCustomTheme(info *Theme) bool { homeDir := dutils.GetHomeDir() dir := path.Join(homeDir, userThemePath, "Custom") if !dutils.IsFileExist(dir) { err := os.MkdirAll(dir, dirPermMode) if err != nil { logger.Debug(err) return false } } filename := path.Join(dir, "theme.ini") var newFile bool if !dutils.IsFileExist(filename) { err := dutils.CopyFile(tempDThemeCustom, filename) if err != nil { logger.Debug(err) return false } newFile = true } kFile := glib.NewKeyFile() defer kFile.Free() _, err := kFile.LoadFromFile(filename, glib.KeyFileFlagsKeepComments| glib.KeyFileFlagsKeepTranslations) if err != nil { return false } kFile.SetString(groupKeyComponent, themeKeyGtk, info.GtkTheme) kFile.SetString(groupKeyComponent, themeKeyIcon, info.IconTheme) kFile.SetString(groupKeyComponent, themeKeyCursor, info.CursorTheme) kFile.SetString(groupKeyComponent, themeKeySound, info.SoundTheme) kFile.SetString(groupKeyComponent, themeKeyBackground, info.Background) kFile.SetString(groupKeyComponent, themeKeyFontName, info.FontName) kFile.SetString(groupKeyComponent, themeKeyFontMono, info.FontMono) kFile.SetInteger(groupKeyComponent, themeKeyFontSize, info.FontSize) _, contents, err := kFile.ToData() if err != nil { return false } m.wLocker.Lock() defer m.wLocker.Unlock() ok := dutils.WriteStringToKeyFile(filename, contents) if newFile && ok { touchFile() } return ok }
func (*GrubTester) TestSetup(c *C.C) { wantSettingsContent := `GRUB_BACKGROUND="<none>" GRUB_CMDLINE_LINUX="locale=zh_CN.UTF-8 url=http://cdimage/nfsroot/deepin-2014/desktop/current/amd64/preseed/deepin.seed initrd=http://cdimage/nfsroot/deepin-2014/desktop/current/amd64/casper/initrd.lz" GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_DEFAULT="0" GRUB_DISTRIBUTOR="` + "`lsb_release -d -s 2> /dev/null || echo Debian`" + `" GRUB_GFXMODE="1200x900" GRUB_THEME="/tmp/dde_daemon_grub2_test/dde_daemon_grub2_test_theme_dir/theme.txt" GRUB_TIMEOUT="5" ` // prepare configFile = tmpBaseDir + "/grub2.json" utils.EnsureDirExist(tmpThemeDir) utils.CopyFile(testGrubThemeBackgroundSourceFile, tmpThemeDir+"/background_source") SetDefaultGrubSettingFile(tmpConfigFile) SetDefaultThemeDir(tmpThemeDir) defer func() { configFile = ConfigFileDefault SetDefaultGrubSettingFile(DefaultGrubSettingFile) SetDefaultThemeDir(DefaultThemeDir) }() g := NewGrub2() var w, h int // setup with target gfxmode utils.CopyFile(testGrubSettingsFile, tmpConfigFile) g.Setup(tmpGfxmode) settingContentBuf, _ := ioutil.ReadFile(tmpConfigFile) c.Check(string(settingContentBuf), C.Equals, wantSettingsContent) g.readSettings() c.Check(g.getSettingDefaultEntry(), C.Equals, "0") c.Check(g.getSettingTimeout(), C.Equals, int32(5)) c.Check(g.getSettingGfxmode(), C.Equals, tmpGfxmode) c.Check(g.getSettingTheme(), C.Equals, tmpThemeDir+"/theme.txt") w, h, _ = graphic.GetImageSize(tmpThemeDir + "/background.png") c.Check(w, C.Equals, 1200) c.Check(h, C.Equals, 900) }
// DoSetThemeBackgroundSourceFile setup a new background source file // for deepin grub2 theme, and then generate the background depends on // screen resolution. func (ge *Grub2Ext) DoSetThemeBackgroundSourceFile(imageFile string, screenWidth, screenHeight uint16) (ok bool, err error) { // if background source file is a symlink, just delete it if utils.IsSymlink(themeBgSrcFile) { os.Remove(themeBgSrcFile) } // backup background source file err = utils.CopyFile(imageFile, themeBgSrcFile) if err != nil { return false, err } // generate a new background return ge.DoGenerateThemeBackground(screenWidth, screenHeight) }
func (u *User) addIconFile(icon string) (string, bool, error) { if isStrInArray(icon, u.IconList) { return icon, false, nil } md5, ok := dutils.SumFileMd5(icon) if !ok { return "", false, fmt.Errorf("Sum file '%s' md5 failed", icon) } dest := path.Join(userCustomIconsDir, u.UserName+"-"+md5) err := os.MkdirAll(path.Dir(dest), 0755) if err != nil { return "", false, err } err = dutils.CopyFile(icon, dest) if err != nil { return "", false, err } return dest, true, nil }
func (*GrubTester) TestSetupGfxmode(c *C.C) { // prepare configFile = tmpBaseDir + "/grub2.json" utils.EnsureDirExist(tmpThemeDir) utils.CopyFile(testGrubThemeBackgroundSourceFile, tmpThemeDir+"/background_source") SetDefaultGrubSettingFile(tmpConfigFile) SetDefaultThemeDir(tmpThemeDir) defer func() { configFile = ConfigFileDefault SetDefaultGrubSettingFile(DefaultGrubSettingFile) SetDefaultThemeDir(DefaultThemeDir) }() g := NewGrub2() var w, h int var sw, sh int tmpsw, tmpsh := getPrimaryScreenBestResolution() sw, sh = int(tmpsw), int(tmpsh) // setup with none gfxmode utils.CopyFile(testGrubSettingsFile, tmpConfigFile) g.Setup("") g.readSettings() c.Check(g.getSettingDefaultEntry(), C.Equals, "0") c.Check(g.getSettingTimeout(), C.Equals, int32(5)) c.Check(g.getSettingGfxmode(), C.Equals, getDefaultGfxmode()) c.Check(g.getSettingTheme(), C.Equals, tmpThemeDir+"/theme.txt") w, h, _ = graphic.GetImageSize(tmpThemeDir + "/background.png") c.Check(w, C.Equals, sw) c.Check(h, C.Equals, sh) // setup with none gfxmode utils.CopyFile(testGrubSettingsFile, tmpConfigFile) g.Setup("auto") g.readSettings() c.Check(g.getSettingDefaultEntry(), C.Equals, "0") c.Check(g.getSettingTimeout(), C.Equals, int32(5)) c.Check(g.getSettingGfxmode(), C.Equals, "auto") c.Check(g.getSettingTheme(), C.Equals, tmpThemeDir+"/theme.txt") w, h, _ = graphic.GetImageSize(tmpThemeDir + "/background.png") c.Check(w, C.Equals, sw) c.Check(h, C.Equals, sh) // setup with wrong gfxmode format // will following error message in this case, so we just disable // all output and recovery it when done oldLogLevel := logger.GetLogLevel() logger.SetLogLevel(log.LevelDisable) defer logger.SetLogLevel(oldLogLevel) utils.CopyFile(testGrubSettingsFile, tmpConfigFile) g.Setup("1024x") g.readSettings() c.Check(g.getSettingDefaultEntry(), C.Equals, "0") c.Check(g.getSettingTimeout(), C.Equals, int32(5)) c.Check(g.getSettingGfxmode(), C.Equals, "1024x") c.Check(g.getSettingTheme(), C.Equals, tmpThemeDir+"/theme.txt") w, h, _ = graphic.GetImageSize(tmpThemeDir + "/background.png") c.Check(w, C.Equals, sw) c.Check(h, C.Equals, sh) }