1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/***************************************************************************
copyright : (C) 2005-2006 by Robby Stephenson
email : robby@periapsis.org
***************************************************************************/
/***************************************************************************
* *
* This file has been modified to match the requirements of KBibTeX. *
* In case of problems or bugs arising from this implementation, please *
* contact the KBibTeX team first. *
* Thomas Fischer <fischer@unix-ag.uni-kl.de> *
* *
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License as *
* published by the Free Software Foundation; *
* *
***************************************************************************/
#ifndef KBIBTEX_Z3950CONNECTION_H
#define KBIBTEX_Z3950CONNECTION_H
#include <tqthread.h>
#include <tqevent.h>
#include <tqdeepcopy.h>
#include <ksharedptr.h>
namespace KBibTeX {
class Z3950ResultFound : public TQCustomEvent {
public:
Z3950ResultFound(const TQString& s);
~Z3950ResultFound();
const TQString& result() const { return m_result; }
static int uid() { return User + 11111; }
private:
TQString m_result;
};
class Z3950ConnectionDone : public TQCustomEvent {
public:
Z3950ConnectionDone(bool more) : TQCustomEvent(uid()), m_type(-1), m_hasMore(more) {}
Z3950ConnectionDone(bool more, const TQString& s, int t) : TQCustomEvent(uid()), m_msg(TQDeepCopy<TQString>(s)), m_type(t), m_hasMore(more) {}
const TQString& message() const { return m_msg; }
int messageType() const { return m_type; }
bool hasMoreResults() const { return m_hasMore; }
static int uid() { return User + 22222; }
private:
TQString m_msg;
int m_type;
bool m_hasMore;
};
class Z3950SyntaxChange : public TQCustomEvent {
public:
Z3950SyntaxChange(const TQString& s) : TQCustomEvent(uid()), m_syntax(TQDeepCopy<TQString>(s)) {}
const TQString& syntax() const { return m_syntax; }
static int uid() { return User + 33333; }
private:
TQString m_syntax;
};
/**
* @author Robby Stephenson
*/
class Z3950Connection : public TQThread {
public:
Z3950Connection(TQObject* fetcher,
const TQString& host,
uint port,
const TQString& dbname,
const TQString& sourceCharSet,
const TQString& syntax,
const TQString& esn);
~Z3950Connection();
void reset();
void setQuery(const TQString& query, unsigned int numHits);
void setUserPassword(const TQString& user, const TQString& pword);
void run();
void abort() { m_aborted = true; }
private:
static TQCString iconvRun(const TQCString& text, const TQString& fromCharSet, const TQString& toCharSet);
static TQString toXML(const TQCString& marc, const TQString& fromCharSet);
bool makeConnection();
void done();
void done(const TQString& message, int type);
TQCString toCString(const TQString& text);
TQString toString(const TQCString& text);
void checkPendingEvents();
class Private;
Private* d;
bool m_connected;
bool m_aborted;
TQObject* m_fetcher;
TQString m_host;
uint m_port;
TQString m_dbname;
TQString m_user;
TQString m_password;
TQString m_sourceCharSet;
TQString m_syntax;
TQString m_pqn;
TQString m_esn;
size_t m_start;
size_t m_limit;
bool m_hasMore;
friend class Z3950ResultFound;
static int resultsLeft;
};
} // end namespace
#endif
|