File: printoutput.cpp

package info (click to toggle)
photoprint 0.4.1-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,568 kB
  • ctags: 4,517
  • sloc: cpp: 46,643; sh: 10,360; ansic: 4,755; makefile: 543; sed: 16
file content (146 lines) | stat: -rw-r--r-- 2,796 bytes parent folder | download
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
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

#include "../miscwidgets/generaldialogs.h"

#include "../support/debug.h"

#include "printoutput.h"
#include "printoutputselector.h"


class PODBHandler : public ConfigDBHandler
{
	public:
	PODBHandler(ConfigFile *inif,const char *section,PrintOutput *po)
		: ConfigDBHandler(inif,section,po), printoutput(po)
	{
	}
	~PODBHandler()
	{
	}
	void LeaveSection()
	{
		Debug[TRACE] << "*** Leaving PrintOutput section" << endl;
		printoutput->DBToQueues();
	}
	private:
	PrintOutput *printoutput;	
};

PrintOutput::PrintOutput(ConfigFile *inif,const char *section) : ConfigDB(Template), PrinterQueues()
{
	Debug[TRACE] << "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);
	}
	Debug[TRACE] << "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;
	str=FindString("Driver");
	if(str[0]=='p' && str[1]=='s')	// Are we printing in PostScript mode?
		SetDataType(PQINFO_POSTSCRIPT);
	else
		SetDataType(PQINFO_RAW);

	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))
		Debug[TRACE] << "Printer queue exists" << endl;
	else
	{
		Debug[TRACE] << "Warning - printer queue not found" << endl;
		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("ResponseHash",""),
	ConfigTemplate()
};