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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_VCL_INC_UNX_CPDMGR_HXX
#define INCLUDED_VCL_INC_UNX_CPDMGR_HXX
#include <config_dbus.h>
#include <config_gio.h>
#if ENABLE_DBUS && ENABLE_GIO
#include <gio/gio.h>
#else
typedef struct _GDBusProxy GDBusProxy;
typedef struct _GDBusConnection GDBusConnection;
#endif
#include <printerinfomanager.hxx>
#include "cupsmgr.hxx"
#define BACKEND_DIR "/usr/share/print-backends"
#define FRONTEND_INTERFACE "/usr/share/dbus-1/interfaces/org.openprinting.Frontend.xml"
#define BACKEND_INTERFACE "/usr/share/dbus-1/interfaces/org.openprinting.Backend.xml"
namespace psp
{
class PPDParser;
struct CPDPrinter
{
const char* id;
const char* name;
const char* info;
const char* location;
const char* make_and_model;
const char* printer_state;
const char* backend_name;
bool is_accepting_jobs;
GDBusProxy* backend;
};
struct CPDPrinterOption
{
OUString name;
OUString default_value;
int num_supported_values;
std::vector<OUString> supported_values;
};
class CPDManager : public PrinterInfoManager
{
#if ENABLE_DBUS && ENABLE_GIO
GDBusConnection * m_pConnection = nullptr;
bool m_aPrintersChanged = true;
std::vector<std::pair<std::string, gchar*>> m_tBackends;
std::unordered_map< std::string, GDBusProxy * > m_pBackends;
std::unordered_map< FILE*, OString, FPtrHash > m_aSpoolFiles;
std::unordered_map< OUString, CPDPrinter * > m_aCPDDestMap;
std::unordered_map< OUString, PPDContext > m_aDefaultContexts;
#endif
CPDManager();
// Function called when CPDManager is destroyed
virtual ~CPDManager() override;
virtual void initialize() override;
#if ENABLE_DBUS && ENABLE_GIO
static void onNameAcquired(GDBusConnection *connection, const char* name, void* user_data);
static void onNameLost (GDBusConnection *, const char *name, void*);
static void printerAdded (GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
const gchar *interface_name,
const gchar *signal_name,
GVariant *parameters,
gpointer user_data);
static void printerRemoved (GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
const gchar *interface_name,
const gchar *signal_name,
GVariant *parameters,
gpointer user_data);
static void getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, const OString& rJobName, int& rNumOptions, GVariant **arr );
#endif
public:
#if ENABLE_DBUS && ENABLE_GIO
// Functions involved in initialization
GDBusProxy * getProxy( std::string target );
void addBackend( std::pair< std::string, GDBusProxy * > pair );
void addTempBackend( std::pair< std::string, gchar* > pair );
std::vector<std::pair<std::string, gchar*>> const & getTempBackends();
void addNewPrinter( const OUString&, const OUString&, CPDPrinter * );
#endif
// Create CPDManager
static CPDManager* tryLoadCPD();
// Create a PPDParser for CPD Printers
const PPDParser* createCPDParser( const OUString& rPrinter );
// Functions related to printing
virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand ) override;
virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString& rFaxNumber ) override;
virtual void setupJobContextData( JobData& rData ) override;
// check if the printer configuration has changed
virtual bool checkPrintersChanged( bool bWait ) override;
// members for administration
// disable for CPD
virtual bool addPrinter( const OUString& rPrinterName, const OUString& rDriverName ) override;
virtual bool removePrinter( const OUString& rPrinterName, bool bCheckOnly ) override;
virtual bool setDefaultPrinter( const OUString& rPrinterName ) override;
};
} // namespace psp
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|