diff options
author | Inokinoki <veyx.shaw@gmail.com> | 2020-09-01 10:09:31 +0200 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2020-09-02 11:40:12 +0800 |
commit | beae287d141c111ac18ccfd5ddf7afa1f23a8945 (patch) | |
tree | 893f51450503bbee477e1541276d3975f6fd95ee /src/PYPCloudCandidates.h | |
parent | afd6134ebdd7d01383f79763e574fab0a227307d (diff) | |
download | ibus-libpinyin-beae287d141c111ac18ccfd5ddf7afa1f23a8945.tar.gz ibus-libpinyin-beae287d141c111ac18ccfd5ddf7afa1f23a8945.tar.xz ibus-libpinyin-beae287d141c111ac18ccfd5ddf7afa1f23a8945.zip |
Add Cloud Input implementation
This implementation adds Cloud Input feature with delayed request and
asynchronous request.
- Support Full Pinyin and Double Pinyin modes
- Support Bopomofo mode
Co-authored-by: lianna07 <liannaxu07@gmail.com>
Co-authored-by: Peng Wu <alexepico@gmail.com>
Diffstat (limited to 'src/PYPCloudCandidates.h')
-rw-r--r-- | src/PYPCloudCandidates.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/PYPCloudCandidates.h b/src/PYPCloudCandidates.h new file mode 100644 index 0000000..aaccdba --- /dev/null +++ b/src/PYPCloudCandidates.h @@ -0,0 +1,99 @@ +/* vim:set et ts=4 sts=4: + * + * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus + * + * Copyright (c) 2018 linyu Xu <liannaxu07@gmail.com> + * Copyright (c) 2020 Weixuan XIAO <veyx.shaw@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __PY_LIB_PINYIN_ClOUD_CANDIDATES_H_ +#define __PY_LIB_PINYIN_ClOUD_CANDIDATES_H_ + +#include "PYString.h" +#include "PYPointer.h" +#include "PYPEnhancedCandidates.h" +#include <vector> +#include <libsoup/soup.h> +#include <json-glib/json-glib.h> +#include "PYConfig.h" + + + +class BaiduCloudCandidatesResponseJsonParser; +class GoogleCloudCandidatesResponseJsonParser; + +namespace PY { + +#define BUFFERLENGTH 2048 +#define CLOUD_MINIMUM_UTF8_TRIGGER_LENGTH 2 + +enum InputMode { + FullPinyin = 0, + DoublePinyin, + Bopomofo +}; + +class PhoneticEditor; + +class CloudCandidates : public EnhancedCandidates<PhoneticEditor> +{ +public: + + CloudCandidates (PhoneticEditor *editor); + ~CloudCandidates(); + + void setInputMode (InputMode mode) { m_input_mode = mode; } + + gboolean processCandidates (std::vector<EnhancedCandidate> & candidates); + + int selectCandidate (EnhancedCandidate & enhanced); + + void cloudAsyncRequest (const gchar* requestStr); + void cloudSyncRequest (const gchar* requestStr, std::vector<EnhancedCandidate> & candidates); + + void delayedCloudAsyncRequest (const gchar* requestStr); + + void updateLookupTable (); + + guint m_source_event_id; + SoupMessage *m_message; + std::string m_last_requested_pinyin; + +private: + static gboolean delayedCloudAsyncRequestCallBack (gpointer user_data); + static void delayedCloudAsyncRequestDestroyCallBack (gpointer user_data); + static void cloudResponseCallBack (GObject *object, GAsyncResult *result, gpointer user_data); + + void processCloudResponse (GInputStream *stream, std::vector<EnhancedCandidate> & candidates); + + /* get internal full pinyin representation */ + String getFullPinyin (); +private: + SoupSession *m_session; + InputMode m_input_mode; + + BaiduCloudCandidatesResponseJsonParser *m_baidu_parser; + GoogleCloudCandidatesResponseJsonParser *m_google_parser; +protected: + std::vector<EnhancedCandidate> m_candidates; +}; + +}; + +#endif + + |