Пример #1
0
func (t *Theme) getThemePreview(themeType string) string {
	var target string
	switch themeType {
	case "gtk":
		target = path.Join("WindowThemes", t.GtkTheme)
	case "icon":
		target = path.Join("IconThemes", t.IconTheme)
	case "cursor":
		target = path.Join("CursorThemes", t.CursorTheme)
	}

	filename := path.Join(os.Getenv("HOME"), userPreviewPath,
		target+"-preview.png")
	if dutils.IsFileExist(filename) {
		return dutils.EncodeURI(filename, dutils.SCHEME_FILE)
	}

	filename = path.Join(systemPreviewPath,
		target+"-preview.png")
	if dutils.IsFileExist(filename) {
		return dutils.EncodeURI(filename, dutils.SCHEME_FILE)
	}

	return ""
}
Пример #2
0
// Default broswer: google-chrome
func copyBroswerConfig(home, lang string) error {
	dest := path.Join(home, ".config/google-chrome")
	if dutils.IsFileExist(dest) {
		return nil
	}

	var (
		override   = "/usr/share/deepin-default-settings/google-chrome/override-chrome-config.tar"
		configLang = fmt.Sprintf("/usr/share/deepin-default-settings/google-chrome/chrome-config-%s.tar", lang)
		config     = "/usr/share/deepin-default-settings/google-chrome/chrome-config.tar"

		broswerConfig string
	)
	switch {
	case dutils.IsFileExist(override):
		broswerConfig = override
	case dutils.IsFileExist(configLang):
		broswerConfig = configLang
	case dutils.IsFileExist(config):
		broswerConfig = config
	}
	if len(broswerConfig) == 0 {
		return fmt.Errorf("Not found broswer configure file")
	}

	_, err := archive.Extracte(broswerConfig, path.Join(home, ".config"))
	return err
}
Пример #3
0
func renameXDGDirs(home, lang string) {
	var (
		desktop   = path.Join(home, "Desktop")
		templates = path.Join(home, "Templates")
	)

	switch lang {
	case "zh_CN":
		if dutils.IsFileExist(desktop) {
			os.Rename(desktop, path.Join(home, "桌面"))
		}

		if dutils.IsFileExist(templates) {
			os.Rename(templates, path.Join(home, "模板"))
			//dutils.CreateFile(path.Join(home, "模板", "文本文件"))
		}
	case "zh_TW":
		if dutils.IsFileExist(desktop) {
			os.Rename(desktop, path.Join(home, "桌面"))
		}

		if dutils.IsFileExist(templates) {
			os.Rename(templates, path.Join(home, "模板"))
			dutils.CreateFile(path.Join(home, "模板", "新增檔案"))
		}
	default:
		if dutils.IsFileExist(templates) {
			dutils.CreateFile(path.Join(templates, "New file"))
		}
	}
}
Пример #4
0
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
}
Пример #5
0
func doGenCursorThumb(forceFlag bool, outDir string) {
	list := getCursorList()
	for _, l := range list {
		dest := getThumbCachePath("--cursor", l.Path, outDir)
		if len(dest) < 1 || (!forceFlag && dutils.IsFileExist(dest)) {
			continue
		}
		bg := getThumbBg()
		if !genCursorThumbnail(l, dest, bg) {
			logger.Debugf("ERROR: Generate Cursor Thumbnail\n")
		}
	}
	if dutils.IsFileExist(XCUR2PNG_OUTDIR) {
		os.RemoveAll(XCUR2PNG_OUTDIR)
	}
}
Пример #6
0
func getCPUInfoFromFile(config string) (string, error) {
	if !dutils.IsFileExist(config) {
		return "", errFileNotExist
	}

	contents, err := ioutil.ReadFile(config)
	if err != nil {
		return "", err
	}

	var (
		info string
		cnt  int
	)
	lines := strings.Split(string(contents), "\n")
	for _, line := range lines {
		if strings.Contains(line, "model name") {
			vars := strings.Split(line, ":")
			if len(vars) != 2 {
				break
			}
			cnt++
			if len(info) == 0 {
				info += vars[1]
			}
		}
	}
	if cnt > 1 {
		info = fmt.Sprintf("%s x %v", info, cnt)
	}

	return strings.TrimSpace(info), nil
}
Пример #7
0
func getDscConfInfo() (isUpdate bool, duration int32) {
	isUpdate = true
	duration = 3

	homeDir := dutils.GetHomeDir()
	filename := path.Join(homeDir, DSC_CONFIG_PATH)
	if !dutils.IsFileExist(filename) {
		return
	}

	str, _ := dutils.ReadKeyFromKeyFile(filename,
		"update", "auto", "")
	if v, ok := str.(string); ok && v == "False" {
		isUpdate = false
	}

	interval, ok1 := dutils.ReadKeyFromKeyFile(filename,
		"update", "interval", int32(0))
	if ok1 {
		if i, ok := interval.(int32); ok {
			duration = int32(i)
		}
	}

	return

}
Пример #8
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
}
Пример #9
0
func isVersionSame() bool {
	versionFile := path.Join(THUMB_CACHE_SYS_PATH, VERSION_FILE)
	if !dutils.IsFileExist(versionFile) {
		err := writeVersionFile(versionFile)
		if err != nil {
			logger.Warning("writeVersionFile failed:", err)
		}
		return false
	}

	contents, err := ioutil.ReadFile(versionFile)
	if err != nil {
		logger.Warning("Read version file failed:", err)
		return false
	}

	if string(contents) == VERSION {
		return true
	}
	if err := writeVersionFile(versionFile); err != nil {
		logger.Warning("writeVersionFile failed:", err)
	}

	return false
}
Пример #10
0
func getPngList(dir string) []string {
	list := []string{}

	if !dutils.IsFileExist(dir) {
		return list
	}

	fp, err := os.Open(dir)
	if err != nil {
		return list
	}
	defer fp.Close()

	names, err1 := fp.Readdirnames(0)
	if err1 != nil {
		return list
	}

	for _, n := range names {
		ok, _ := regexp.MatchString(`\.png$`, n)
		if !ok {
			continue
		}

		filename := path.Join(dir, n)
		list = append(list, filename)
	}

	return list
}
Пример #11
0
func searchString(key, md5 string) []string {
	list := []string{}
	cachePath, ok := getCachePath()
	if !ok {
		return list
	}

	filename := path.Join(cachePath, md5)
	if !dutils.IsFileExist(filename) {
		logger.Warningf("'%s' not exist", filename)
		return list
	}

	datas := []dataInfo{}
	if !readDatasFromFile(&datas, filename) {
		return list
	}

	matchers := getMatchers(key)
	var matchRes = matchResInfo{}
	for _, v := range datas {
		getMatchReuslt(&v, matchers, &matchRes)
	}

	list = sortMatchResult(&matchRes)

	return list
}
Пример #12
0
func searchStartWithString(key, md5 string) []string {
	list := []string{}
	cachePath, ok := getCachePath()
	if !ok {
		return list
	}

	filename := path.Join(cachePath, md5)
	if !dutils.IsFileExist(filename) {
		logger.Warningf("'%s' not exist", filename)
		return list
	}

	datas := []dataInfo{}
	if !readDatasFromFile(&datas, filename) {
		return list
	}

	match := regexp.MustCompile(fmt.Sprintf(`(?i)^(%s)`, key))
	for _, v := range datas {
		if match.MatchString(v.Key) {
			list = append(list, v.Value)
		}
	}

	return list
}
Пример #13
0
//Default config: /usr/share/config/kdm/kdmrc
func getKDMAutoLoginUser(file string) (string, error) {
	if !dutils.IsFileExist(file) {
		return "", fmt.Errorf("Not found this file: %s", file)
	}

	v, exist := dutils.ReadKeyFromKeyFile(file,
		"X-:0-Core", "AutoLoginEnable", true)
	if !exist {
		return "", nil
	}

	enable, ok := v.(bool)
	if !ok {
		return "", fmt.Errorf("The value's type error.")
	}

	if !enable {
		return "", nil
	}

	v, exist = dutils.ReadKeyFromKeyFile(file,
		"X-:0-Core", "AutoLoginUser", "")
	if !exist {
		return "", nil
	}

	var name string
	name, ok = v.(string)
	if !ok {
		return "", fmt.Errorf("The value's type error.")
	}

	return name, nil
}
Пример #14
0
func isAppInBlackList() bool {
	X := getXUtil()
	if X == nil {
		return false
	}

	xid, _ := getActiveWindow(X)
	pid, _ := getWindowPid(X, xid)

	filename := fmt.Sprintf("/proc/%v/cmdline", pid)
	if !dutils.IsFileExist(filename) {
		return false
	}

	contents, err := ioutil.ReadFile(filename)
	if err != nil {
		logger.Warningf("ReadFile '%s' failed: %v", filename, err)
		return false
	}

	blackList := zoneSettings().GetStrv("black-list")
	for _, target := range blackList {
		if strings.Contains(string(contents), target) {
			return true
		}
	}

	return false
}
Пример #15
0
func CopyFile(src, dst string, copyFlag CopyFlag) error {
	srcStat, err := os.Lstat(src)
	if err != nil {
		return err
	}

	if srcStat.IsDir() {
		return fmt.Errorf("error src is a directory: %s", src)
	}

	if utils.IsFileExist(dst) {
		dstStat, err := os.Lstat(dst)
		if err != nil {
			return fmt.Errorf("error os.Lstat dst %s: %s", dst, err)
		}

		if dstStat.IsDir() {
			dst = path.Join(dst, path.Base(src))
		} else {
			if (copyFlag & CopyFileOverWrite) == 0 {
				return fmt.Errorf("error dst %s is alreadly exist", dst)
			}
		}
	}

	return copyFileAux(src, dst, copyFlag)
}
Пример #16
0
func (cursor *CursorTheme) Set(theme string) error {
	if !IsNameInInfoList(theme, cursor.infoList) {
		return errInvalidTheme
	}

	// Ignore xsettings error
	setThemeViaXSettings(theme)
	fixedQtCursor(theme)

	dir := path.Join(os.Getenv("HOME"), ".icons/default")
	if !dutils.IsFileExist(dir) {
		err := os.MkdirAll(dir, dirModePerm)
		if err != nil {
			return err
		}
	}
	filename := path.Join(dir, "index.theme")
	ok := dutils.WriteKeyToKeyFile(filename,
		"Icon Theme", "Inherits", theme)
	if !ok {
		return errWriteCursor
	}

	return nil
}
Пример #17
0
func getImageList(dir string) ([]string, bool) {
	list := []string{}
	if !dutils.IsFileExist(dir) {
		return list, false
	}

	f, err := os.Open(dir)
	if err != nil {
		logger.Debugf("Open '%s' failed: %v", dir, err)
		return list, false
	}
	defer f.Close()

	if infos, err := f.Readdir(0); err != nil {
		logger.Debugf("Readdir '%s' failed: %v", dir, err)
		return list, false
	} else {
		for _, i := range infos {
			if i.IsDir() {
				continue
			}
			name := strings.ToLower(i.Name())
			ok1, _ := regexp.MatchString(`\.jpe?g$`, name)
			ok2, _ := regexp.MatchString(`\.png$`, name)
			if ok1 || ok2 {
				list = append(list, path.Join(dir, i.Name()))
			}
		}
	}

	return list, true
}
Пример #18
0
func getBgDir(dir string) ([]string, bool) {
	list := []string{}
	if !dutils.IsFileExist(dir) {
		return list, false
	}

	f, err := os.Open(dir)
	if err != nil {
		logger.Debugf("Open '%s' failed: %v", dir, err)
		return list, false
	}
	defer f.Close()

	if infos, err := f.Readdir(0); err != nil {
		logger.Debugf("Readdir '%s' failed: %v", dir, err)
		return list, false
	} else {
		conditions := []string{PERSON_BG_NAME}
		for _, i := range infos {
			if !i.IsDir() {
				continue
			}
			filename := path.Join(dir, i.Name())
			if filterTheme(filename, conditions) {
				list = append(list, path.Join(filename, PERSON_BG_NAME))
			}
		}
	}

	return list, true
}
Пример #19
0
func (icon *IconTheme) GetThumbnail(theme string) string {
	var thumb string
	for _, info := range icon.infoList {
		if theme != info.BaseName {
			continue
		}

		if info.FileFlag == FileFlagSystemOwned {
			thumb = path.Join(systemThumbPath,
				theme+"-thumbnail.png")
		} else {
			thumb = path.Join(os.Getenv("HOME"),
				userThumbPath,
				theme+"-thumbnail.png")
		}
		if dutils.IsFileExist(thumb) {
			break
		}

		thumb = GetThumbnail("--icon", info.FilePath)
		break
	}

	return thumb
}
Пример #20
0
func (s *DesktopTestSuite) TestSendRemoveDesktop(c *C.C) {
	srcFile := path.Join(s.testDataDir, "deepin-software-center.desktop")
	destFile := path.Join(s.testDataDir, "Desktop/deepin-software-center.desktop")
	sendToDesktop(srcFile)
	c.Assert(utils.IsFileExist(destFile), C.Equals, true)

	st, err := os.Lstat(destFile)
	if err != nil {
		c.Skip(err.Error())
	}

	var execPerm os.FileMode = 0100
	c.Assert(st.Mode().Perm()&execPerm, C.Equals, execPerm)

	removeFromDesktop(srcFile)
	c.Assert(utils.IsFileExist(destFile), C.Equals, false)
}
Пример #21
0
func (bg *Background) IsValueValid(value string) bool {
	filename := dutils.DecodeURI(value)
	if dutils.IsFileExist(filename) &&
		graphic.IsSupportedImage(filename) {
		return true
	}

	return false
}
Пример #22
0
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)
}
Пример #23
0
func (m *Manager) isVersionRight() bool {
	versionFile := path.Join(os.Getenv("HOME"), _VERSION_DIR, "version")
	if !dutils.IsFileExist(versionFile) {
		m.newVersionFile()
		return false
	}

	return true
}
Пример #24
0
func touchFile() {
	dir := path.Join(os.Getenv("HOME"), userThemePath)
	filename := path.Join(dir, "__emit-signal__")

	if !dutils.IsFileExist(filename) {
		os.MkdirAll(filename, dirPermMode)
	} else {
		os.RemoveAll(filename)
	}
}
Пример #25
0
func isKeySupported(key string) bool {
	switch key {
	case "disable-touchpad":
		return isTouchpadExist()
	case "deepin-translator":
		return dutils.IsFileExist("/usr/bin/deepin-translator")
	}

	return true
}
Пример #26
0
func copyDeepinManuals(home, lang string) error {
	var (
		langDesc = map[string]string{
			"zh_CN": "用户手册",
		}

		langDoc = map[string]string{
			"zh_CN": "文档",
			"zh_TW": "文件",
			"en_US": "Documents",
		}
	)

	src := path.Join("/usr/share/doc/deepin-manuals", lang)
	if !dutils.IsFileExist(src) {
		return fmt.Errorf("Not found the file or directiry: %v", src)
	}

	destName, ok := langDesc[lang]
	if !ok {
		return fmt.Errorf("The language '%s' does not support", lang)
	}

	docName, ok := langDoc[lang]
	if !ok {
		docName = "Documents"
	}
	doc := path.Join(home, docName)
	if !dutils.IsFileExist(doc) {
		err := os.MkdirAll(doc, 0755)
		if err != nil {
			return err
		}
	}

	dest := path.Join(doc, destName)
	if dutils.IsFileExist(dest) {
		return nil
	}

	return dutils.SymlinkFile(src, dest)
}
Пример #27
0
func (u *User) GetLargeIcon() string {
	baseName := path.Base(u.IconFile)
	dir := path.Dir(u.IconFile)

	filename := path.Join(dir, "bigger", baseName)
	if !dutils.IsFileExist(filename) {
		return ""
	}

	return filename
}
Пример #28
0
func getVersionFromLsb(lsbfile string) (string, error) {
	if !dutils.IsFileExist(lsbfile) {
		return "", errFileNotExist
	}

	value, err := getValueByKeyFromFile(lsbfile, "DISTRIB_RELEASE", "=")
	if err != nil {
		return "", err
	}

	return value, nil
}
Пример #29
0
func getDirList() []string {
	var list []string

	list = append(list, systemThemePath)
	userDir := path.Join(os.Getenv("HOME"), userThemePath)
	if !dutils.IsFileExist(userDir) {
		os.MkdirAll(userDir, 0755)
	}
	list = append(list, userDir)

	return list
}
Пример #30
0
func getIconTypeInfo(iconPath string) iconTypeInfo {
	typeInfo := iconTypeInfo{}
	if !dutils.IsFileExist(iconPath) {
		return typeInfo
	}

	dirList := getIconDirList(iconPath)
	if len(dirList) < 1 {
		return typeInfo
	}

	for _, l := range dirList {
		if strings.Contains(l, NAME_APP_DIR) {
			if len(typeInfo.appsList) < 1 {
				typeInfo.typeCnt++
			}

			typeInfo.appsList = append(typeInfo.appsList, l)
		} else if strings.Contains(l, NAME_PLACE_DIR) {
			if len(typeInfo.placesList) < 1 {
				typeInfo.typeCnt++
			}

			typeInfo.placesList = append(typeInfo.placesList, l)
		} else if strings.Contains(l, NAME_DEVICES_DIR) {
			if len(typeInfo.devicesList) < 1 {
				typeInfo.typeCnt++
			}

			typeInfo.devicesList = append(typeInfo.devicesList, l)
		} else if strings.Contains(l, NAME_ACTIONS_DIR) {
			if len(typeInfo.actionsList) < 1 {
				typeInfo.typeCnt++
			}

			typeInfo.actionsList = append(typeInfo.actionsList, l)
		} else if strings.Contains(l, NAME_STATUS_DIR) {
			if len(typeInfo.statusList) < 1 {
				typeInfo.typeCnt++
			}

			typeInfo.statusList = append(typeInfo.statusList, l)
		} else if strings.Contains(l, NAME_EMBLEMS_DIR) {
			if len(typeInfo.emblemsList) < 1 {
				typeInfo.typeCnt++
			}

			typeInfo.emblemsList = append(typeInfo.emblemsList, l)
		}
	}

	return typeInfo
}