#include "language.h"
#include "tmtext.h"
#include "tmdatabase.h"
-#include "tmsocket.h"
#include <QObject>
#include <QString>
#include <QJsonArray>
#include <QMap>
#include <QQueue>
+#include <QAbstractSocket>
#include <QIcon>
{
class Service;
-
-template <typename T>
-class Dispatcher
-{
-public:
- Dispatcher() : m_token_count(0) { }
-
- int size() const { return m_map.size(); }
-
- void clear() { m_map.clear(); }
-
- int set(T p)
- {
- int token = 0;
- if(m_tokens.isEmpty()) token = ++m_token_count;
- else token = m_tokens.dequeue();
-
- m_map.insert(token, p);
- return token;
- }
-
- T get(int token)
- {
- T result;
- QMap<int, T>::iterator it = m_map.find(token);
-
- if(it != m_map.end())
- {
- result = it.value();
- m_tokens.append(it.key());
- m_map.erase(it);
- }
- return result;
- }
-
-private:
- QMap<int, T> m_map;
- QQueue<int> m_tokens;
- int m_token_count;
-};
+class SocketConnection;
+class EditorWidget;
+class CandidateWidget;
class WordringConnection : public QObject
{
public:
WordringConnection(Settings *settings, Service *service);
- bool find_sentence(QString site_name, int scode, int tcode,
- QString ssentence, qint32 token);
+ bool find_sentence(sentence_data_type const &sdata);
- bool insert_sentence(QString site_name, int scode, int tcode,
- QString ssentence, QString tsentence, QByteArray word_link);
+ bool insert_sentence(sentence_data_type const &sdata,
+ sentence_data_type const &tdata);
+ bool remove_sentence(
+ sentence_data_type const &sdata,
+ sentence_data_type const &tdata);
public slots:
void onConnected();
Service(Settings *settings, QObject *parent = 0);
~Service();
+ // エディタ。
+ EditorWidget* editor_widget();
+ void set_editor_widget(EditorWidget *editor);
+ CandidateWidget* candidate_widget();
+ void set_candidate_widget(CandidateWidget *candidate);
+
+ void change_edit_mode(bool mode);
+
+ // SocketConnection
+ void attach(SocketConnection *connection);
+ void detach(SocketConnection *connection);
+ void set_current_connection(SocketConnection *connection);
+
// CRC32
void setup_crc_table();
quint32 crc32(QString const &string);
// 言語プラグイン
void load_languages(QString const &path);
+ Language* find_language(int code);
+
Text::pointer divide_into_sentences(int code, QString string);
Text::pointer divide_into_words(int code, Text::pointer sentence);
+ QString normalize(int code, QString string);
+
// データベース
- quint32 find_site_id(QString host_name);
+ quint32 find_site_id(QString host);
+ void insert_sentence(TextSentence::pointer sentence);
+ void remove_sentence(TextSentence::pointer sentence);
+ void find_sentence(TextSentence::pointer sentence);
- void insert_sentence(QString site_name, int scode, int tcode,
- TextSentence::pointer sentence);
+ void find_candidates(TextSentence::pointer sentence);
- void find_sentence(QString site_name, int scode, int tcode,
- int segment_id, int index, TextSentence::pointer sentence,
- SocketConnection::pointer socket);
private:
- sentence_data_type::pointer stuff_sentence_data(int code, Text::pointer text);
public:
signals:
/*!
void languageLoaded(int code, QString name, QIcon icon);
public slots:
- void sentence_found(sentence_data_type::pointer result, qint32 token);
- void sentence_not_found(QString site_name, qint32 scode, qint32 tcode,
- QString ssentence, qint32 token);
+ // データベースから
+ void sentence_found(sentence_data_type result, TextSentence::weak_pointer token);
+ void sentence_not_found(TextSentence::weak_pointer token);
+ void sentence_inserted(quint32 source_id, quint32 target_id, TextSentence::weak_pointer token);
+
+ void candidate_found(candidate_data_type candidate,
+ TextSentence::weak_pointer token);
public:
- void sentence_found(QString site, qint32 scode, qint32 tcode,
- QString ssentence, QString tsentence, QByteArray json,
- quint32 user_id, qint32 token);
- void sentence_not_found(quint32 token);
- void do_wordring_disconnected();
+ // サーバから
+ void sentence_found(QString sstring, sentence_data_type const &result);
private:
Settings *m_settings;
- quint32 m_crc_table[256];
QMap<int, Language*> m_languages;
+ EditorWidget *m_editor_widget;
+ CandidateWidget *m_candidate_widget;
+
QThread *m_database_thread;
Database *m_database;
- Dispatcher<dispatcher_data_type> m_database_dispatcher;
WordringConnection *m_wordring;
- Dispatcher<dispatcher_data_type> m_wordring_dispatcher;
- int m_wordring_dispatcher_limit;
+
+ QSet<SocketConnection*> m_connections;
+ SocketConnection *m_current_connection;
+
+ quint32 m_crc_table[256];
};
+Q_DECLARE_METATYPE(sentence_data_type)
+Q_DECLARE_METATYPE(candidate_data_type)
+Q_DECLARE_METATYPE(TextSentence::weak_pointer)
+
} // namespace TM
#endif // TMSERVICE_H