summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2020-06-23 14:22:38 +0800
committerPeng Wu <alexepico@gmail.com>2020-07-21 15:27:51 +0800
commit035d5fdda849c2b1d369fbfcb6ebe705ca2c3221 (patch)
treef61eb8da86682c902cebf8bc245548301c5486d3
parentdc67c6437dd2f3a5790c7065f03631a123e144db (diff)
downloadibus-libpinyin-035d5fdda849c2b1d369fbfcb6ebe705ca2c3221.tar.gz
ibus-libpinyin-035d5fdda849c2b1d369fbfcb6ebe705ca2c3221.tar.xz
ibus-libpinyin-035d5fdda849c2b1d369fbfcb6ebe705ca2c3221.zip
support network dictionary timestamp in GSettings
-rw-r--r--src/PYConfig.cc41
-rw-r--r--src/PYConfig.h31
-rw-r--r--src/PYPConfig.cc26
-rw-r--r--src/PYPConfig.h2
4 files changed, 100 insertions, 0 deletions
diff --git a/src/PYConfig.cc b/src/PYConfig.cc
index 081182e..e4cba9d 100644
--- a/src/PYConfig.cc
+++ b/src/PYConfig.cc
@@ -69,6 +69,9 @@ Config::initDefaultValues (void)
m_punct_switch = "<Control>period";
m_both_switch = "";
m_trad_switch = "<Control><Shift>f";
+
+ m_network_dictionary_start_timestamp = 0;
+ m_network_dictionary_end_timestamp = 0;
}
@@ -119,6 +122,44 @@ Config::read (const gchar * name,
return defval;
}
+gint64
+Config::read (const gchar * name,
+ gint64 defval)
+{
+ GVariant *value = NULL;
+ if ((value = g_settings_get_value (m_settings, name)) != NULL) {
+ if (g_variant_classify (value) == G_VARIANT_CLASS_INT64)
+ return g_variant_get_int64 (value);
+ }
+
+ g_warn_if_reached ();
+ return defval;
+}
+
+gboolean
+Config::write (const gchar * name, bool val)
+{
+ return g_settings_set_boolean (m_settings, name, val);
+}
+
+gboolean
+Config::write (const gchar * name, gint val)
+{
+ return g_settings_set_int (m_settings, name, val);
+}
+
+gboolean
+Config::write (const gchar * name, const gchar * val)
+{
+ return g_settings_set_string (m_settings, name, val);
+}
+
+gboolean
+Config::write (const gchar * name, gint64 val)
+{
+ return g_settings_set_int64 (m_settings, name, val);
+}
+
gboolean
Config::valueChanged (const std::string &schema_id,
const std::string &name,
diff --git a/src/PYConfig.h b/src/PYConfig.h
index 07f4eca..09477b9 100644
--- a/src/PYConfig.h
+++ b/src/PYConfig.h
@@ -78,12 +78,30 @@ public:
std::string tradSwitch (void) const { return m_trad_switch; }
std::string openccConfig (void) const { return m_opencc_config; }
+ gint64 networkDictionaryStartTimestamp (void) const
+ { return m_network_dictionary_start_timestamp; }
+ gint64 networkDictionaryEndTimestamp (void) const
+ { return m_network_dictionary_end_timestamp; }
+
+public:
+ /* write option */
+ virtual gboolean networkDictionaryStartTimestamp (gint64 timestamp)
+ { return FALSE; }
+ virtual gboolean networkDictionaryEndTimestamp (gint64 timestamp)
+ { return FALSE; }
+
protected:
bool read (const gchar * name, bool defval);
gint read (const gchar * name, gint defval);
std::string read (const gchar * name, const gchar * defval);
+ gint64 read (const gchar * name, gint64 defval);
void initDefaultValues (void);
+ gboolean write (const gchar * name, bool val);
+ gboolean write (const gchar * name, gint val);
+ gboolean write (const gchar * name, const gchar * val);
+ gboolean write (const gchar * name, gint64 val);
+
virtual void readDefaultValues (void);
virtual gboolean valueChanged (const std::string &schema_id,
const std::string &name,
@@ -137,6 +155,8 @@ protected:
std::string m_both_switch;
std::string m_trad_switch;
+ gint64 m_network_dictionary_start_timestamp;
+ gint64 m_network_dictionary_end_timestamp;
};
@@ -173,5 +193,16 @@ normalizeGVariant (GVariant *value, const std::string &defval)
return g_variant_get_string (value, NULL);
}
+static inline gint64
+normalizeGVariant (GVariant *value, gint64 defval)
+{
+ if (value == NULL ||
+ g_variant_classify (value) != G_VARIANT_CLASS_INT64) {
+ g_warn_if_reached ();
+ return defval;
+ }
+ return g_variant_get_int64 (value);
+}
+
};
#endif
diff --git a/src/PYPConfig.cc b/src/PYPConfig.cc
index 7e03884..7e896f5 100644
--- a/src/PYPConfig.cc
+++ b/src/PYPConfig.cc
@@ -65,6 +65,8 @@ const gchar * const CONFIG_LETTER_SWITCH = "letter-switch";
const gchar * const CONFIG_PUNCT_SWITCH = "punct-switch";
const gchar * const CONFIG_BOTH_SWITCH = "both-switch";
const gchar * const CONFIG_TRAD_SWITCH = "trad-switch";
+const gchar * const CONFIG_NETWORK_DICTIONARY_START_TIMESTAMP = "network-dictionary-start-timestamp";
+const gchar * const CONFIG_NETWORK_DICTIONARY_END_TIMESTAMP = "network-dictionary-end-timestamp";
const pinyin_option_t PINYIN_DEFAULT_OPTION =
PINYIN_INCOMPLETE |
@@ -92,6 +94,20 @@ LibPinyinConfig::~LibPinyinConfig (void)
m_settings = NULL;
}
+gboolean
+LibPinyinConfig::networkDictionaryStartTimestamp (gint64 timestamp)
+{
+ m_network_dictionary_start_timestamp = timestamp;
+ return write (CONFIG_NETWORK_DICTIONARY_START_TIMESTAMP, timestamp);
+}
+
+gboolean
+LibPinyinConfig::networkDictionaryEndTimestamp (gint64 timestamp)
+{
+ m_network_dictionary_end_timestamp = timestamp;
+ return write (CONFIG_NETWORK_DICTIONARY_END_TIMESTAMP, timestamp);
+}
+
void
LibPinyinConfig::initDefaultValues (void)
{
@@ -130,6 +146,9 @@ LibPinyinConfig::initDefaultValues (void)
m_punct_switch = "<Control>period";
m_both_switch = "";
m_trad_switch = "<Control><Shift>f";
+
+ m_network_dictionary_start_timestamp = 0;
+ m_network_dictionary_end_timestamp = 0;
}
static const struct {
@@ -244,6 +263,9 @@ LibPinyinConfig::readDefaultValues (void)
m_both_switch = read (CONFIG_BOTH_SWITCH, "");
m_trad_switch = read (CONFIG_TRAD_SWITCH, "<Control><Shift>f");
+ m_network_dictionary_start_timestamp = read (CONFIG_NETWORK_DICTIONARY_START_TIMESTAMP, (gint64) 0);
+ m_network_dictionary_end_timestamp = read (CONFIG_NETWORK_DICTIONARY_END_TIMESTAMP, (gint64) 0);
+
/* fuzzy pinyin */
if (read (CONFIG_FUZZY_PINYIN, false))
m_option_mask |= PINYIN_AMB_ALL;
@@ -325,6 +347,10 @@ LibPinyinConfig::valueChanged (const std::string &schema_id,
m_both_switch = normalizeGVariant (value, std::string (""));
} else if (CONFIG_TRAD_SWITCH == name) {
m_trad_switch = normalizeGVariant (value, std::string ("<Control><Shift>f"));
+ } else if (CONFIG_NETWORK_DICTIONARY_START_TIMESTAMP == name) {
+ m_network_dictionary_start_timestamp = normalizeGVariant (value, (gint64) 0);
+ } else if (CONFIG_NETWORK_DICTIONARY_END_TIMESTAMP == name) {
+ m_network_dictionary_end_timestamp = normalizeGVariant (value, (gint64) 0);
}
/* fuzzy pinyin */
else if (CONFIG_FUZZY_PINYIN == name) {
diff --git a/src/PYPConfig.h b/src/PYPConfig.h
index 9f0fea4..b08fd5a 100644
--- a/src/PYPConfig.h
+++ b/src/PYPConfig.h
@@ -39,6 +39,8 @@ protected:
virtual ~LibPinyinConfig (void);
public:
+ virtual gboolean networkDictionaryStartTimestamp (gint64 timestamp);
+ virtual gboolean networkDictionaryEndTimestamp (gint64 timestamp);
protected:
void initDefaultValues (void);