less Q3 (remove a lot of unused Q3 headers, port small things)
[kdenetwork.git] / kdict / dict.h
blob35ccb15400560c4fc10a3dd7457835f9fefc6f52
1 /* -------------------------------------------------------------
3 dict.h (part of The KDE Dictionary Client)
5 Copyright (C) 2000-2001 Christian Gebauer <gebauer@kde.org>
6 (C) by Matthias Hölzer 1998
8 This file is distributed under the Artistic License.
9 See LICENSE for details.
11 -------------------------------------------------------------
13 JobData used for data transfer between Client and Interface
14 DictAsyncClient all network related stuff happens here in an asynchrous thread
15 DictInterface interface for DictAsyncClient, job management
17 -------------------------------------------------------------*/
19 #ifndef _DICT_H_
20 #define _DICT_H_
22 #include <pthread.h>
23 #include <q3ptrlist.h>
24 #include <qsocketnotifier.h>
25 //Added by qt3to4:
26 #include <Q3CString>
28 class QSocketNotifier;
29 struct in_addr;
32 //********* JobData ******************************************
35 class JobData
38 public:
40 enum QueryType { //type of transaction
41 TDefine=0,
42 TGetDefinitions,
43 TMatch,
44 TShowDatabases,
45 TShowDbInfo,
46 TShowStrategies,
47 TShowInfo,
48 TUpdate
51 enum ErrType { // error codes
52 ErrNoErr=0,
53 ErrCommunication, // display result!
54 ErrTimeout,
55 ErrBadHost,
56 ErrConnect, // display result!
57 ErrRefused,
58 ErrNotAvailable,
59 ErrSyntax,
60 ErrCommandNotImplemented,
61 ErrAccessDenied,
62 ErrAuthFailed,
63 ErrInvalidDbStrat,
64 ErrNoDatabases,
65 ErrNoStrategies,
66 ErrServerError, // display result!
67 ErrMsgTooLong
70 JobData(QueryType Ntype,bool NnewServer,QString const& Nserver,int Nport,
71 int NidleHold, int Ntimeout, int NpipeSize, QString const& Nencoding, bool NAuthEnabled,
72 QString const& Nuser, QString const& Nsecret, unsigned int NheadLayout);
74 QueryType type;
75 ErrType error;
77 bool canceled;
78 int numFetched;
79 QString result;
80 QStringList matches;
82 QString query;
83 QStringList defines;
85 bool newServer;
86 QString server;
87 int port, timeout, pipeSize, idleHold;
88 QString encoding;
89 bool authEnabled;
90 QString user, secret;
91 QStringList databases,strategies;
92 QString strategy;
93 unsigned int headLayout;
97 //********* DictAsyncClient ******************************************
100 class DictAsyncClient
103 public:
105 DictAsyncClient(int NfdPipeIn, int NfdPipeOut);
106 ~DictAsyncClient();
108 static void* startThread(void* pseudoThis);
110 void insertJob(JobData *newJob);
111 void removeJob();
113 private:
115 void waitForWork(); // main loop
116 void define();
117 bool getDefinitions();
118 bool match();
119 void showDatabases();
120 void showDbInfo();
121 void showStrategies();
122 void showInfo();
123 void update();
125 void openConnection(); // connect, handshake and authorization
126 void closeSocket();
127 void doQuit(); // send "quit" without timeout, without checks, close connection
128 bool waitForRead(); // used by getNextIntoBuffer()
129 bool waitForWrite(); // used by sendBuffer() & connect()
130 void clearPipe(); // remove start/stop signal
132 bool sendBuffer(); // send cmdBuffer to the server
133 bool getNextLine(); // set thisLine to next complete line of input
134 bool nextResponseOk(int code); // reads next line and checks the response code
135 bool getNextResponse(int &code); // reads next line and returns the response code
136 void handleErrors();
138 void resultAppend(const char* str);
139 void resultAppend(QString str);
141 JobData *job;
142 char *input;
143 Q3CString cmdBuffer;
144 const unsigned int inputSize;
145 char *thisLine, *nextLine, *inputEnd;
146 int fdPipeIn,fdPipeOut; //IPC-Pipes to/from async thread
147 int tcpSocket,timeout,idleHold;
148 QTextCodec *codec;
152 //********* DictInterface *************************************************
154 class DictInterface : public QObject
156 Q_OBJECT
158 public:
160 DictInterface();
161 ~DictInterface();
163 public slots:
165 void serverChanged(); // inform the client when server settings get changed
166 void stop(); // cancel all pending jobs
168 void define(const QString &query);
169 void getDefinitions(QStringList query);
170 void match(const QString &query);
171 void showDbInfo(const QString &db); // fetch detailed db info
172 void showDatabases(); // fetch misc. info...
173 void showStrategies();
174 void showInfo();
175 void updateServer(); // get info about databases & strategies the server knows
177 signals:
179 void infoReady(); // updateServer done
180 void resultReady(const QString &result, const QString &query); // define done
181 void matchReady(const QStringList &result); // match done
182 void started(const QString &message); // Client is active now, activate indicator
183 void stopped(const QString &message); // Client is now halted, deactivate indicator
185 private slots:
187 void clientDone();
189 private:
191 JobData* generateQuery(JobData::QueryType type, QString query);
192 void insertJob(JobData* job); // insert in job list, if nesscary cancel/remove previous jobs
193 void startClient(); // send start signal
194 void cleanPipes(); // empty the pipes, so that notifier stops firing
196 QSocketNotifier *notifier;
197 int fdPipeIn[2],fdPipeOut[2]; //IPC-Pipes to/from async thread
198 pthread_t threadID;
199 DictAsyncClient *client;
200 Q3PtrList<JobData> jobList;
201 bool newServer,clientDoneInProgress;
204 extern DictInterface *interface;
206 #endif