1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_VCL_INC_UNX_CPDMGR_HXX 21 #define INCLUDED_VCL_INC_UNX_CPDMGR_HXX 22 23 #include <config_dbus.h> 24 #include <config_gio.h> 25 26 #if ENABLE_DBUS && ENABLE_GIO 27 #include <gio/gio.h> 28 #else 29 typedef struct _GDBusProxy GDBusProxy; 30 typedef struct _GDBusConnection GDBusConnection; 31 #endif 32 33 #include <printerinfomanager.hxx> 34 #include "cupsmgr.hxx" 35 36 #define BACKEND_DIR "/usr/share/print-backends" 37 #define FRONTEND_INTERFACE "/usr/share/dbus-1/interfaces/org.openprinting.Frontend.xml" 38 #define BACKEND_INTERFACE "/usr/share/dbus-1/interfaces/org.openprinting.Backend.xml" 39 40 namespace psp 41 { 42 43 class PPDParser; 44 45 struct CPDPrinter 46 { 47 const char* id; 48 const char* name; 49 const char* info; 50 const char* location; 51 const char* make_and_model; 52 const char* printer_state; 53 const char* backend_name; 54 bool is_accepting_jobs; 55 GDBusProxy* backend; 56 }; 57 58 class CPDManager : public PrinterInfoManager 59 { 60 #if ENABLE_DBUS && ENABLE_GIO 61 GDBusConnection * m_pConnection = nullptr; 62 bool m_aPrintersChanged = true; 63 std::vector<std::pair<std::string, gchar*>> m_tBackends; 64 std::unordered_map< std::string, GDBusProxy * > m_pBackends; 65 std::unordered_map< FILE*, OString, FPtrHash > m_aSpoolFiles; 66 std::unordered_map< OUString, CPDPrinter * > m_aCPDDestMap; 67 std::unordered_map< OUString, PPDContext > m_aDefaultContexts; 68 #endif 69 CPDManager(); 70 // Function called when CPDManager is destroyed 71 virtual ~CPDManager() override; 72 73 virtual void initialize() override; 74 75 #if ENABLE_DBUS && ENABLE_GIO 76 static void onNameAcquired(GDBusConnection *connection, const gchar* name, gpointer user_data); 77 static void onNameLost (GDBusConnection *, const gchar *name, gpointer); 78 static void printerAdded (GDBusConnection *connection, 79 const gchar *sender_name, 80 const gchar *object_path, 81 const gchar *interface_name, 82 const gchar *signal_name, 83 GVariant *parameters, 84 gpointer user_data); 85 static void printerRemoved (GDBusConnection *connection, 86 const gchar *sender_name, 87 const gchar *object_path, 88 const gchar *interface_name, 89 const gchar *signal_name, 90 GVariant *parameters, 91 gpointer user_data); 92 93 static void getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, const OString& rJobName, int& rNumOptions, GVariant **arr ); 94 #endif 95 96 public: 97 #if ENABLE_DBUS && ENABLE_GIO 98 // Functions involved in initialization 99 GDBusProxy* getProxy(const std::string& target); 100 void addBackend( std::pair< std::string, GDBusProxy * > pair ); 101 void addTempBackend(const std::pair<std::string, gchar*>& pair); 102 std::vector<std::pair<std::string, gchar*>> const & getTempBackends() const; 103 void addNewPrinter( const OUString&, const OUString&, CPDPrinter * ); 104 #endif 105 106 // Create CPDManager 107 static CPDManager* tryLoadCPD(); 108 109 // Create a PPDParser for CPD Printers 110 const PPDParser* createCPDParser( const OUString& rPrinter ); 111 112 // Functions related to printing 113 virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand ) override; 114 virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString& rFaxNumber ) override; 115 virtual void setupJobContextData( JobData& rData ) override; 116 117 // check if the printer configuration has changed 118 virtual bool checkPrintersChanged( bool bWait ) override; 119 }; 120 121 } // namespace psp 122 123 #endif 124 125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 126 127