1 #ifndef DICTTRACKER_H 2 #define DICTTRACKER_H 3 4 #include "conf.h" 5 #include "net/dict.h" 6 7 8 namespace Dict { 9 10 class Page; 11 12 class Tracker : public QObject 13 { 14 Q_OBJECT 15 16 public: 17 Tracker(Connection *dict, Page *word, Page *match = 0); 18 19 void define(const QString &query); 20 void match(const QString &query, const QString &strategy); 21 void info(const QString &query, const QString &text); 22 void cancel(); restart()23 void restart() { dictinit = Stopped; init(); } 24 void setup(); 25 setCorrect(bool on)26 void setCorrect(bool on) { search.corrections = on; } setMatchPage(Page * match)27 void setMatchPage(Page *match) { matchPage = (search.matchPage) ? match : 0; } setAutoMatch(bool on)28 void setAutoMatch(bool on) { search.autoMatch = on; } setAutoStrategy(int strategy)29 void setAutoStrategy(int strategy) { search.autoStrategy = strategy; } 30 void setDefaultDatabase(int database); setMatchFilter(bool on)31 void setMatchFilter(bool on) { search.filter = on; } setMatchList(bool list)32 void setMatchList(bool list) { matchlist = list; } matchList()33 bool matchList() { return search.matchPage; } 34 35 private: 36 enum Init { Stopped, Started, Databases, Strategies = 4 }; 37 int dictinit; 38 struct State { 39 bool defining, matching, correcting, appending, automatching; 40 void clear(); 41 void automatch(); 42 } state; 43 void init(); 44 bool init(Init state); 45 46 int hits, misses, dbcount; reset()47 void reset() { hits = misses = 0; } count()48 int count() { return hits + misses; } 49 50 void clear(); 51 void done(); 52 void suggestions(); 53 void automatches(); 54 55 Connection *dict; 56 Page *wordPage, *matchPage; 57 bool matchlist; 58 QString query, strategy; 59 QStringList database; 60 QString defaultDatabase, defaultStrategy; 61 SearchConf search; 62 63 public Q_SLOTS: 64 void response(const Response &response); 65 void setDatabase(const QStringList &database); 66 void setStrategy(const QString &strategy); 67 68 Q_SIGNALS: 69 void words(); 70 void matches(bool); 71 void corrections(); 72 void loading(bool); 73 void databases(const List &list); 74 void strategies(const List &list); 75 void progress(int current, int total); 76 }; 77 78 } 79 80 #endif 81