~ubuntu-branches/ubuntu/karmic/photoprint/karmic

« back to all changes in this revision

Viewing changes to stp_support/printerqueues_win32.c

  • Committer: Bazaar Package Importer
  • Author(s): Milan Zamazal
  • Date: 2007-05-01 16:32:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070501163213-ni1933khtg9fdvn5
Tags: 0.3.5-2
Move to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
};
17
17
 
18
18
 
 
19
enum pqoutputmode
 
20
{
 
21
        PQMODE_PRINT,
 
22
        PQMODE_FILE
 
23
};
 
24
 
 
25
 
19
26
struct pqprivate
20
27
{
21
28
        void (*Dispose)(struct pqprivate *pp);
22
29
        char *currentqueue;
23
30
        struct printernode *first;
24
31
        HANDLE printer;
 
32
        enum pqoutputmode mode;
 
33
        char *(*getfilecallback)(void *userdata);
 
34
        void *userdata;
 
35
        FILE *outfile;
25
36
};
26
37
 
27
38
 
74
85
}
75
86
 
76
87
 
77
 
pqp_buildqueuelist(struct pqprivate *pp)
 
88
static void pqp_buildqueuelist(struct pqprivate *pp)
78
89
{
79
90
        DWORD dwSizeNeeded;
80
91
        DWORD dwNumItems;
94
105
                }
95
106
        }
96
107
        HeapFree ( GetProcessHeap (), 0, lpInfo );
 
108
 
 
109
        printernode_create(pp,PRINTERQUEUE_SAVETOFILE);
97
110
}
98
111
 
99
112
 
121
134
}
122
135
 
123
136
 
 
137
static void setgetfilenamecallback(struct pqinfo *pq,char *(*func)(void *userdata),void *userdata)
 
138
{
 
139
        fprintf(stderr,"Setting filename callback.\n");
 
140
        pq->priv->getfilecallback=func;
 
141
        pq->priv->userdata=userdata;
 
142
}
 
143
 
 
144
 
124
145
static int getprintercount(struct pqinfo *pq)
125
146
{
126
147
        int count=0;
149
170
 
150
171
static void setprinterqueue(struct pqinfo *pq,const char *queue)
151
172
{
 
173
        if(pq->priv->currentqueue)
 
174
                free(pq->priv->currentqueue);
152
175
        if(queue)
153
 
        {
154
 
                if(pq->priv->currentqueue)
155
 
                        free(pq->priv->currentqueue);
156
176
                pq->priv->currentqueue=strdup(queue);
157
 
        }
 
177
        else
 
178
                pq->priv->currentqueue=NULL;
 
179
}
 
180
 
 
181
 
 
182
static const char *getprinterqueue(struct pqinfo *pq)
 
183
{
 
184
        return(pq->priv->currentqueue);
158
185
}
159
186
 
160
187
 
173
200
 
174
201
static int initialisejob(struct pqinfo *pq)
175
202
{
176
 
        static DOC_INFO_1 mydi={"Gutenprint output",NULL,NULL};
177
 
        BOOL result=OpenPrinter(pq->priv->currentqueue,&pq->priv->printer,NULL);
178
 
        if(result)
179
 
                StartDocPrinter(pq->priv->printer,1,(LPBYTE)&mydi);
180
 
 
181
 
        return(result);
 
203
        fprintf(stderr,"In initialisejob() - checking mode\n");
 
204
        if(strcmp(pq->priv->currentqueue,PRINTERQUEUE_SAVETOFILE)==0)
 
205
        {
 
206
                char *fn=NULL;
 
207
 
 
208
                pq->priv->mode=PQMODE_FILE;
 
209
 
 
210
                fprintf(stderr,"Getting filename...\n");
 
211
 
 
212
                if(pq->priv->getfilecallback)
 
213
                        fn=pq->priv->getfilecallback(pq->priv->userdata);
 
214
 
 
215
                pq->priv->outfile=NULL;
 
216
                if(fn)
 
217
                        pq->priv->outfile=fopen(fn,"wb");
 
218
                free(fn);
 
219
 
 
220
                if(!pq->priv->outfile)
 
221
                        return(0);
 
222
                return(1);
 
223
        }
 
224
        else
 
225
        {
 
226
                static DOC_INFO_1 mydi={"Gutenprint output",NULL,NULL};
 
227
                BOOL result;
 
228
 
 
229
                fprintf(stderr,"Getting printer...\n");
 
230
 
 
231
                result=OpenPrinter(pq->priv->currentqueue,&pq->priv->printer,NULL);
 
232
                if(result)
 
233
                        StartDocPrinter(pq->priv->printer,1,(LPBYTE)&mydi);
 
234
                pq->priv->mode=PQMODE_PRINT;
 
235
                return(result);
 
236
        }
182
237
}
183
238
 
184
239
 
185
240
static void initialisepage(struct pqinfo *pq)
186
241
{
187
 
        if(pq->priv->printer)
188
 
                StartPagePrinter(pq->priv->printer);
 
242
        if(pq->priv->mode==PQMODE_PRINT)
 
243
        {
 
244
                if(pq->priv->printer)
 
245
                        StartPagePrinter(pq->priv->printer);
 
246
        }
189
247
}
190
248
 
191
249
 
192
250
static void endpage(struct pqinfo *pq)
193
251
{
194
 
        if(pq->priv->printer)
195
 
                EndPagePrinter(pq->priv->printer);
 
252
        if(pq->priv->mode==PQMODE_PRINT)
 
253
        {
 
254
                if(pq->priv->printer)
 
255
                        EndPagePrinter(pq->priv->printer);
 
256
        }
196
257
}
197
258
 
198
259
 
199
260
static void endjob(struct pqinfo *pq)
200
261
{
201
 
        if(pq->priv->printer)
202
 
        {
203
 
                EndDocPrinter(pq->priv->printer);
204
 
                ClosePrinter(pq->priv->printer);
205
 
        }
206
 
        pq->priv->printer=NULL;
 
262
        if(pq->priv->mode==PQMODE_PRINT)
 
263
        {
 
264
                if(pq->priv->printer)
 
265
                {
 
266
                        EndDocPrinter(pq->priv->printer);
 
267
                        ClosePrinter(pq->priv->printer);
 
268
                }
 
269
                pq->priv->printer=NULL;
 
270
        }
 
271
        else
 
272
        {
 
273
                if(pq->priv->outfile)
 
274
                        fclose(pq->priv->outfile);
 
275
                pq->priv->outfile=NULL;
 
276
        }
207
277
}
208
278
 
209
279
 
210
280
static int writedata(struct pqinfo *pq,const char *data,int bytecount)
211
281
{
212
 
        long written=0;
213
 
        WritePrinter(pq->priv->printer,(char *)data,bytecount,&written);
214
 
        return((written!=0));
 
282
        if(pq->priv->mode==PQMODE_PRINT)
 
283
        {
 
284
                long written=0;
 
285
                WritePrinter(pq->priv->printer,(char *)data,bytecount,&written);
 
286
                return((written!=0));
 
287
        }
 
288
        else
 
289
        {
 
290
                long written=fwrite((char *)data,1,bytecount,pq->priv->outfile);
 
291
                return((written!=0));
 
292
        }
215
293
}
216
294
 
217
295
 
230
308
                pq->GetPrinterCount=getprintercount;
231
309
                pq->GetPrinterName=getprintername;
232
310
                pq->SetPrinterQueue=setprinterqueue;
 
311
                pq->GetPrinterQueue=getprinterqueue;
233
312
                pq->GetDriver=getdriver;
234
313
                pq->GetPPD=getppd;
235
314
                pq->InitialiseJob=initialisejob;
238
317
                pq->EndJob=endjob;
239
318
                pq->CancelJob=canceljob;
240
319
                pq->WriteData=writedata;
 
320
                pq->SetGetFilenameCallback=setgetfilenamecallback;
241
321
 
242
322
                if(!(pq->priv=pqprivate_create()))
243
323
                {