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 132 133 134 135
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#include "support/generaldialogs.h"
#include "printoutput.h"
#include "pp_printoutput.h"
class PODBHandler : public ConfigDBHandler
{
public:
PODBHandler(ConfigFile *inif,const char *section,PrintOutput *po)
: ConfigDBHandler(inif,section,po), printoutput(po)
{
}
~PODBHandler()
{
}
void LeaveSection()
{
cerr << "*** Leaving PrintOutput section" << endl;
printoutput->DBToQueues();
}
private:
PrintOutput *printoutput;
};
PrintOutput::PrintOutput(ConfigFile *inif,const char *section) : ConfigDB(Template), PrinterQueues()
{
cerr << "In PrintOutput constructor..." << endl;
new PODBHandler(inif,section,this);
const char *defaultqueue=FindString("Queue");
if(strlen(defaultqueue)==0 && GetPrinterCount()>0)
{
char *queue=GetPrinterName(0);
if(queue)
{
SetString("Queue",queue);
char *driver=GetPrinterDriver(queue);
SetString("Driver",driver);
free(driver);
free(queue);
}
else
SetString("Driver",DEFAULT_PRINTER_DRIVER);
}
cerr << "Done..." << endl;
}
class Consumer_Queue : public Consumer
{
public:
Consumer_Queue(PrinterQueues &pq,const char *queuename) : pq(pq)
{
pq.SetPrinterQueue(queuename);
if(!pq.InitialiseJob())
throw "Can't initialise!";
pq.InitialisePage();
}
virtual ~Consumer_Queue()
{
pq.EndPage();
pq.EndJob();
}
virtual bool Write(const char *buffer, int length)
{
return(pq.WriteData(buffer,length));
}
virtual void Cancel()
{
pq.CancelJob();
}
protected:
PrinterQueues &pq;
};
Consumer *PrintOutput::GetConsumer()
{
const char *str;
if(strlen(str=FindString("Queue")))
{
try
{
Consumer *result=new Consumer_Queue(*this,str);
return(result);
}
catch(const char *err)
{
return(NULL);
}
}
else
return(NULL);
}
void PrintOutput::DBToQueues()
{
const char *tmp=FindString("Queue");
if(PrinterQueueExists(tmp))
cerr << "Printer queue exists" << endl;
else
{
cerr << "Warning - printer queue not found" << endl;
pp_printoutput_queue_dialog(this);
tmp=FindString("Queue");
}
SetPrinterQueue(tmp);
tmp=FindString("Command");
SetCustomCommand(tmp);
}
void PrintOutput::QueuesToDB()
{
const char *tmp=GetPrinterQueue();
SetString("Queue",tmp);
tmp=GetCustomCommand();
SetString("Command",tmp);
}
ConfigTemplate PrintOutput::Template[]=
{
ConfigTemplate("Queue",""), ConfigTemplate("Driver",""),
ConfigTemplate("Command",""),
ConfigTemplate()
};
|