1 //C-  -*- C++ -*-
2 //C- -------------------------------------------------------------------
3 //C- DjView4
4 //C- Copyright (c) 2006-  Leon Bottou
5 //C-
6 //C- This software is subject to, and may be distributed under, the
7 //C- GNU General Public License, either version 2 of the license,
8 //C- or (at your option) any later version. The license should have
9 //C- accompanied the software or you may obtain a copy of the license
10 //C- from the Free Software Foundation at http://www.fsf.org .
11 //C-
12 //C- This program is distributed in the hope that it will be useful,
13 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //C- GNU General Public License for more details.
16 //C-  ------------------------------------------------------------------
17 
18 #ifndef QDJVU_H
19 #define QDJVU_H
20 
21 #if AUTOCONF
22 # include "config.h"
23 #endif
24 
25 // The following definition allow for using
26 // this file without the libdjvu include files.
27 
28 #ifndef DDJVUAPI_H
29 typedef struct ddjvu_context_s    ddjvu_context_t;
30 typedef union  ddjvu_message_s    ddjvu_message_t;
31 typedef struct ddjvu_job_s        ddjvu_job_t;
32 typedef struct ddjvu_document_s   ddjvu_document_t;
33 typedef struct ddjvu_page_s       ddjvu_page_t;
34 #endif
35 #ifndef MINIEXP_H
36 typedef struct miniexp_s* miniexp_t;
37 #endif
38 
39 
40 // Qt includes
41 
42 #include <QObject>
43 #include <QString>
44 #include <QUrl>
45 
46 
47 // The following classes integrate the ddjvuapi with
48 // the Qt memory management and event management scheme.
49 // All ddjvuapi events are converted into signals sent
50 // when the Qt event loop is called. These signal are
51 // emitted by all objects listed in the event message.
52 //
53 // All classes below define implicit conversion
54 // into pointers to the corresponding ddjvuapi objects.
55 
56 class QDjVuContext;
57 class QDjVuDocument;
58 class QDjVuDocumentPrivate;
59 class QDjVuPage;
60 class QDjVuJob;
61 
62 
63 class QDjVuContext : public QObject
64 {
65   Q_OBJECT
66   Q_PROPERTY(long cacheSize READ cacheSize WRITE setCacheSize)
67 
68 private:
69   static void callback(ddjvu_context_t *context, void *closure);
70   ddjvu_context_t *context;
71   bool flag;  // might become private pointer in the future
72 
73 protected:
74   virtual bool handle(ddjvu_message_t*);
75 
76 public:
77   virtual ~QDjVuContext();
78   QDjVuContext(const char *programname=0, QObject *parent=0);
79   long cacheSize() const;
80   void setCacheSize(long);
81   virtual bool event(QEvent*);
82   operator ddjvu_context_t*() { return context; }
83 
84 signals:
85   void error(QString msg, QString filename, int lineno);
86   void info(QString msg);
87 };
88 
89 
90 class QDjVuDocument : public QObject
91 {
92   Q_OBJECT
93 
94 private:
95   friend class QDjVuContext;
96   friend class QDjVuPage;
97   friend class QDjVuJob;
98   ddjvu_document_t *document;
99   QDjVuDocumentPrivate *priv;
100 
101 protected:
102   virtual bool handle(ddjvu_message_t*);
103 
104 public:
105   virtual ~QDjVuDocument();
106   QDjVuDocument(QObject *parent);
107   QDjVuDocument(bool autoDelete=false, QObject *parent=0);
108   void ref();
109   void deref();
110   bool setFileName(QDjVuContext *ctx, QString filename, bool cache=true);
111 protected:
112   bool setUrl(QDjVuContext *ctx, QUrl url);
113   bool setUrl(QDjVuContext *ctx, QUrl url, bool cache);
114   virtual void newstream(int streamid, QString name, QUrl url);
115 public:
116   void streamWrite(int streamid, const char *data, unsigned long len );
117   void streamClose(int streamid, bool stop = false);
118   operator ddjvu_document_t*() { return document; }
isValid()119   virtual bool isValid() { return document != 0; }
120 public:
121   int runningProcesses(void);
122   miniexp_t getDocumentAnnotations();
123   miniexp_t getDocumentOutline();
124   miniexp_t getPageAnnotations(int pageno, bool start=true);
125   miniexp_t getPageText(int pageno, bool start=true);
126 
127 
128 signals:
129   void error(QString msg, QString filename, int lineno);
130   void info(QString msg);
131   void docinfo(void);
132   void pageinfo(void);
133   void thumbnail(int pagenum);
134   void idle(void);
135 };
136 
137 
138 class QDjVuPage : public QObject
139 {
140   Q_OBJECT
141 
142 private:
143   friend class QDjVuContext;
144   friend class QDjVuDocument;
145   ddjvu_page_t *page;
146   int pageno; // might become private pointer in the future
147 
148 protected:
149   virtual bool handle(ddjvu_message_t*);
150 
151 public:
152   virtual ~QDjVuPage();
153   QDjVuPage(QDjVuDocument *doc, int pageno, QObject *parent=0);
154   operator ddjvu_page_t*() { return page; }
isValid()155   bool isValid() { return page!=0; }
156   int pageNo();
157 
158 signals:
159   void error(QString msg, QString filename, int lineno);
160   void info(QString msg);
161   void chunk(QString chunkid);
162   void pageinfo();
163   void relayout();
164   void redisplay();
165 };
166 
167 
168 class QDjVuJob : public QObject
169 {
170   Q_OBJECT
171 
172 private:
173   friend class QDjVuContext;
174   friend class QDjVuDocument;
175   ddjvu_job_t *job;
176 
177 protected:
178   virtual bool handle(ddjvu_message_t*);
179 
180 public:
181   virtual ~QDjVuJob();
182   QDjVuJob(ddjvu_job_t *job, QObject *parent=0);
183   operator ddjvu_job_t*() { return job; }
184 
185 signals:
186   void error(QString msg, QString filename, int lineno);
187   void info(QString msg);
188   void progress(int percent);
189 };
190 
191 
192 
193 
194 #endif
195 
196 /* -------------------------------------------------------------
197    Local Variables:
198    c++-font-lock-extra-types: ( "\\sw+_t" "Q[A-Z]\\sw*[a-z]\\sw*" )
199    End:
200    ------------------------------------------------------------- */
201