示例#1
0
func NewManager() (*Manager, error) {
	var m = &Manager{}

	var err error
	m.td1, err = timedate1.NewTimedate1("org.freedesktop.timedate1",
		"/org/freedesktop/timedate1")
	if err != nil {
		return nil, err
	}
	m.setPropBool(&m.CanNTP, "CanNTP", m.td1.CanNTP.Get())
	m.setPropBool(&m.NTP, "NTP", m.td1.NTP.Get())
	m.setPropBool(&m.LocalRTC, "LocalRTC", m.td1.LocalRTC.Get())
	m.setPropString(&m.Timezone, "Timezone", m.td1.Timezone.Get())

	m.settings = gio.NewSettings(timedateSchema)
	m.Use24HourFormat = property.NewGSettingsBoolProperty(
		m, "Use24HourFormat",
		m.settings, settingsKey24Hour)
	m.DSTOffset = property.NewGSettingsIntProperty(
		m, "DSTOffset",
		m.settings, settingsKeyDSTOffset)
	m.UserTimezones = property.NewGSettingsStrvProperty(
		m, "UserTimezones",
		m.settings, settingsKeyTimezoneList)
	m.AddUserTimezone(m.Timezone)

	return m, nil
}
func setTimezoneByLocale(locale string) error {
	tm, err := timedate1.NewTimedate1("org.freedesktop.timedate1",
		"/org/freedesktop/timedate1")
	if err != nil {
		return err
	}
	defer timedate1.DestroyTimedate1(tm)

	var zone string
	switch locale {
	case "zh_CN.UTF-8":
		zone = "Asia/Shanghai"
	case "zh_TW.UTF-8":
		zone = "Asia/Taipei"
	default:
		zone = "UTC"
	}

	return tm.SetTimezone(zone, false)
}