xref: /haiku/src/servers/print/PrintServerApp.h (revision 99d027cd0238c1d86da86d7c3f4200509ccc61a6)
1 /*
2  * Copyright 2001-2010, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ithamar R. Adema
7  *		Michael Pfeiffer
8  */
9 #ifndef _PRINT_SERVER_APP_H
10 #define _PRINT_SERVER_APP_H
11 
12 #include <Application.h>
13 #include <Bitmap.h>
14 #include <Catalog.h>
15 #include <OS.h>
16 #include <String.h>
17 
18 #include "FolderWatcher.h"
19 #include "ResourceManager.h"
20 #include "Settings.h"
21 
22 class Printer;
23 class Transport;
24 
25 // The global BLocker for synchronisation.
26 extern BLocker *gLock;
27 
28 // The print_server application.
29 class PrintServerApp : public BApplication, public FolderListener {
30 	private:
31 		typedef BApplication Inherited;
32 
33 	public:
34 		PrintServerApp(status_t *err);
35 		~PrintServerApp();
36 
37 		void Acquire();
38 		void Release();
39 
40 		bool QuitRequested();
41 		void MessageReceived(BMessage *msg);
42 		void NotifyPrinterDeletion(Printer *printer);
43 
44 		// Scripting support, see PrintServerApp.Scripting.cpp
45 		status_t GetSupportedSuites(BMessage *msg);
46 		void HandleScriptingCommand(BMessage *msg);
47 		Printer *GetPrinterFromSpecifier(BMessage *msg);
48 		Transport *GetTransportFromSpecifier(BMessage *msg);
49 		BHandler *ResolveSpecifier(BMessage *msg, int32 index, BMessage *spec,
50 			int32 form, const char *prop);
51 	private:
52 		bool OpenSettings(BFile &file, const char *name, bool forReading);
53 		void LoadSettings();
54 		void SaveSettings();
55 
56 		status_t SetupPrinterList();
57 
58 		void HandleSpooledJobs();
59 
60 		status_t SelectPrinter(const char *printerName);
61 		status_t CreatePrinter(const char *printerName, const char *driverName,
62 			const char *connection, const char *transportName,
63 			const char *transportPath);
64 
65 		void RegisterPrinter(BDirectory *node);
66 		void UnregisterPrinter(Printer *printer);
67 
68 		// FolderListener
69 		void EntryCreated(node_ref *node, entry_ref *entry);
70 		void EntryRemoved(node_ref *node);
71 		void AttributeChanged(node_ref *node);
72 
73 		status_t StoreDefaultPrinter();
74 		status_t RetrieveDefaultPrinter();
75 
76 		status_t FindPrinterNode(const char *name, BNode &node);
77 
78 		// "Classic" BeOS R5 support, see PrintServerApp.R5.cpp
79 		static status_t async_thread(void *data);
80 		void AsyncHandleMessage(BMessage *msg);
81 		void Handle_BeOSR5_Message(BMessage *msg);
82 
83 		ResourceManager fResourceManager;
84 		Printer *fDefaultPrinter;
85 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
86 		size_t fIconSize;
87 		uint8 *fSelectedIcon;
88 #else
89 		BBitmap *fSelectedIconMini;
90 		BBitmap *fSelectedIconLarge;
91 #endif
92 		vint32 fReferences;
93 		sem_id fHasReferences;
94 		Settings *fSettings;
95 		bool fUseConfigWindow;
96 		FolderWatcher *fFolder;
97 };
98 
99 #endif
100