6 #include "tmdatabase.h"
14 #include <QAbstractSocket>
31 class SocketConnection;
33 class WordringConnection : public QObject
37 WordringConnection(Settings *settings, Service *service);
39 bool find_sentence(sentence_data_type const &sdata);
41 bool insert_sentence(sentence_data_type const &sdata,
42 sentence_data_type const &tdata);
44 sentence_data_type const &sdata,
45 sentence_data_type const &tdata);
49 void onDisconnected();
50 void onError(QAbstractSocket::SocketError e);
52 void onTextMessageReceived(QString const &message);
53 void onBinaryMessageReceived(QByteArray const &message);
59 void sentence_found(QJsonObject json);
60 void sentence_not_found(QJsonObject json);
67 QQueue<QByteArray> m_requests;
68 int m_request_limit; /*!< 待機できるリクエストの制限値 */
71 class Service : public QObject
75 struct dispatcher_data_type
77 SocketConnection::pointer connection;
83 Service(Settings *settings, QObject *parent = 0);
87 void attach(SocketConnection *connection);
88 void detach(SocketConnection *connection);
91 void setup_crc_table();
92 quint32 crc32(QString const &string);
93 quint32 crc32(int code, QString const &string);
96 void load_languages(QString const &path);
98 Text::pointer divide_into_sentences(int code, QString string);
99 Text::pointer divide_into_words(int code, Text::pointer sentence);
101 QString normalize(int code, QString string);
104 quint32 find_site_id(QString host);
106 void insert_sentence(TextSentence::pointer sentence);
107 void remove_sentence(TextSentence::pointer sentence);
109 void find_sentence(TextSentence::pointer sentence);
114 * \brief 言語プラグインが読み込まれたときに発火するシグナルです。
115 * \param code 言語コードです。
117 * \param icon 言語を表現するアイコンです。
119 void languageLoaded(int code, QString name, QIcon icon);
123 void sentence_found(sentence_data_type result, TextSentence::weak_pointer token);
124 void sentence_not_found(TextSentence::weak_pointer token);
125 void sentence_inserted(quint32 source_id, quint32 target_id, TextSentence::weak_pointer token);
129 void sentence_found(QString sstring, sentence_data_type const &result);
132 Settings *m_settings;
134 QMap<int, Language*> m_languages;
136 QThread *m_database_thread;
137 Database *m_database;
139 WordringConnection *m_wordring;
141 QSet<SocketConnection*> m_connections;
142 quint32 m_crc_table[256];
145 Q_DECLARE_METATYPE(sentence_data_type)
146 Q_DECLARE_METATYPE(TextSentence::weak_pointer)
150 #endif // TMSERVICE_H