// LoadFile loads a Cairo-Dock configuration file as *CDConfig. func LoadFile(configFile, configDefault string) (*CDConfig, error) { pKeyF, e := keyfile.NewFromFile(configFile, keyfile.FlagsKeepComments|keyfile.FlagsKeepTranslations) if e != nil { return nil, e } return &CDConfig{ KeyFile: *pKeyF, BaseStorage: cftype.BaseStorage{ File: configFile, Default: configDefault, }, }, nil }
// loadDefault gives access to a field value. // func (conf *CDConfig) loadDefault() error { if conf.def != nil { // already loaded. return nil } fileDefault := conf.FileDefault() if fileDefault == "" { // no path return errors.New("no default file path") } kf, e := keyfile.NewFromFile(fileDefault, keyfile.FlagsKeepComments|keyfile.FlagsKeepTranslations) if e != nil { return e } conf.def = kf return nil }
// ListThemeDesktopIcon builds a list of desktop icon-themes in system and user dir. // func (SourceCommon) ListThemeDesktopIcon() []Field { dirs := []string{DirIconsSystem} usr, e := user.Current() if e == nil { dirs = append([]string{filepath.Join(usr.HomeDir, DirIconsUser)}, dirs...) // prepend ~/.icons } var list []Field for _, dir := range dirs { files, e := ioutil.ReadDir(dir) // Get all files in the given directories. if e != nil { continue } for _, info := range files { fullpath := filepath.Join(dir, info.Name()) // and only keep dirs. if !info.IsDir() { continue } file := filepath.Join(fullpath, "index.theme") // Check if a theme index file exists. if _, e = os.Stat(file); e != nil { continue } kf, e := keyfile.NewFromFile(file, keyfile.FlagsNone) // Keyfile required. if e != nil { continue } hidden, _ := kf.Bool("Icon Theme", "Hidden") hasdirs := kf.HasKey("Icon Theme", "Directories") name, _ := kf.String("Icon Theme", "Name") kf.Free() if hidden || !hasdirs || name == "" { // Check theme settings. continue } list = append(list, Field{Key: info.Name(), Name: name}) } } return list }