xref: /haiku/src/preferences/printers/PrinterListView.h (revision 51c4f366c44d737baae30adee0c202d6656b6e55)
1dc90a8c5SPhilippe Houdoin /*
2dc90a8c5SPhilippe Houdoin  * Copyright 2001-2010, Haiku.
3dc90a8c5SPhilippe Houdoin  * Distributed under the terms of the MIT License.
4dc90a8c5SPhilippe Houdoin  *
5dc90a8c5SPhilippe Houdoin  * Authors:
6dc90a8c5SPhilippe Houdoin  *		Michael Pfeiffer
7dc90a8c5SPhilippe Houdoin  */
8dc90a8c5SPhilippe Houdoin #ifndef _PRINTERS_LISTVIEW_H
9dc90a8c5SPhilippe Houdoin #define _PRINTERS_LISTVIEW_H
10dc90a8c5SPhilippe Houdoin 
11dc90a8c5SPhilippe Houdoin 
12dc90a8c5SPhilippe Houdoin #include <Directory.h>
13dc90a8c5SPhilippe Houdoin #include <Entry.h>
14dc90a8c5SPhilippe Houdoin #include <Messenger.h>
15dc90a8c5SPhilippe Houdoin #include <ListView.h>
16dc90a8c5SPhilippe Houdoin #include <String.h>
17dc90a8c5SPhilippe Houdoin 
18dc90a8c5SPhilippe Houdoin #include "FolderWatcher.h"
19dc90a8c5SPhilippe Houdoin 
20dc90a8c5SPhilippe Houdoin 
21dc90a8c5SPhilippe Houdoin class SpoolFolder;
22dc90a8c5SPhilippe Houdoin class PrinterItem;
23dc90a8c5SPhilippe Houdoin class PrinterListView;
24dc90a8c5SPhilippe Houdoin class BBitmap;
25dc90a8c5SPhilippe Houdoin class PrintersWindow;
26dc90a8c5SPhilippe Houdoin 
27dc90a8c5SPhilippe Houdoin 
28dc90a8c5SPhilippe Houdoin struct PrinterListLayoutData
29dc90a8c5SPhilippe Houdoin {
30dc90a8c5SPhilippe Houdoin 	float	fLeftColumnMaximumWidth;
31dc90a8c5SPhilippe Houdoin 	float	fRightColumnMaximumWidth;
32dc90a8c5SPhilippe Houdoin };
33dc90a8c5SPhilippe Houdoin 
34dc90a8c5SPhilippe Houdoin 
35dc90a8c5SPhilippe Houdoin 
36dc90a8c5SPhilippe Houdoin class PrinterListView : public BListView, public FolderListener {
37dc90a8c5SPhilippe Houdoin public:
38dc90a8c5SPhilippe Houdoin 								PrinterListView(BRect frame);
39dc90a8c5SPhilippe Houdoin 								~PrinterListView();
40dc90a8c5SPhilippe Houdoin 
41dc90a8c5SPhilippe Houdoin 			void				AttachedToWindow();
42dc90a8c5SPhilippe Houdoin 			bool				QuitRequested();
43dc90a8c5SPhilippe Houdoin 
44dc90a8c5SPhilippe Houdoin 			void				BuildPrinterList();
45dc90a8c5SPhilippe Houdoin 			PrinterItem*		SelectedItem() const;
46dc90a8c5SPhilippe Houdoin 			void				UpdateItem(PrinterItem* item);
47dc90a8c5SPhilippe Houdoin 
48dc90a8c5SPhilippe Houdoin 			PrinterItem*		ActivePrinter() const;
49dc90a8c5SPhilippe Houdoin 			void 				SetActivePrinter(PrinterItem* item);
50dc90a8c5SPhilippe Houdoin 
51dc90a8c5SPhilippe Houdoin private:
52dc90a8c5SPhilippe Houdoin 		typedef BListView Inherited;
53dc90a8c5SPhilippe Houdoin 
54dc90a8c5SPhilippe Houdoin 			void 				_AddPrinter(BDirectory& printer, bool calculateLayout);
55dc90a8c5SPhilippe Houdoin 			void				_LayoutPrinterItems();
56dc90a8c5SPhilippe Houdoin 			PrinterItem*		_FindItem(node_ref* node) const;
57dc90a8c5SPhilippe Houdoin 
58dc90a8c5SPhilippe Houdoin 			void				EntryCreated(node_ref* node,
59dc90a8c5SPhilippe Houdoin 									entry_ref* entry);
60dc90a8c5SPhilippe Houdoin 			void				EntryRemoved(node_ref* node);
61dc90a8c5SPhilippe Houdoin 			void				AttributeChanged(node_ref* node);
62dc90a8c5SPhilippe Houdoin 
63dc90a8c5SPhilippe Houdoin 			FolderWatcher*		fFolder;
64dc90a8c5SPhilippe Houdoin 			PrinterItem*		fActivePrinter;
65dc90a8c5SPhilippe Houdoin 			PrinterListLayoutData	fLayoutData;
66dc90a8c5SPhilippe Houdoin };
67dc90a8c5SPhilippe Houdoin 
68dc90a8c5SPhilippe Houdoin 
69dc90a8c5SPhilippe Houdoin class PrinterItem : public BListItem {
70dc90a8c5SPhilippe Houdoin public:
71dc90a8c5SPhilippe Houdoin 								PrinterItem(PrintersWindow* window,
72dc90a8c5SPhilippe Houdoin 									const BDirectory& node,
73dc90a8c5SPhilippe Houdoin 									PrinterListLayoutData& layoutData);
74dc90a8c5SPhilippe Houdoin 								~PrinterItem();
75dc90a8c5SPhilippe Houdoin 
76dc90a8c5SPhilippe Houdoin 			void				GetColumnWidth(BView* view, float& leftColumn,
77dc90a8c5SPhilippe Houdoin 									float& rightColumn);
78dc90a8c5SPhilippe Houdoin 
79dc90a8c5SPhilippe Houdoin 			void				DrawItem(BView* owner, BRect bounds,
80dc90a8c5SPhilippe Houdoin 									bool complete);
81dc90a8c5SPhilippe Houdoin 			void				Update(BView* owner, const BFont* font);
82dc90a8c5SPhilippe Houdoin 
83dc90a8c5SPhilippe Houdoin 			bool				Remove(BListView* view);
84dc90a8c5SPhilippe Houdoin 			bool				IsActivePrinter() const;
85dc90a8c5SPhilippe Houdoin 			bool				HasPendingJobs() const;
86dc90a8c5SPhilippe Houdoin 
Name()87dc90a8c5SPhilippe Houdoin 			const char* 		Name() const { return fName.String(); }
Driver()88e8e66c5cSPhilippe Houdoin 			const char*			Driver() const { return fDriverName.String(); }
Transport()89e8e66c5cSPhilippe Houdoin 			const char*			Transport() const { return fTransport.String(); }
TransportAddress()90e8e66c5cSPhilippe Houdoin 			const char*			TransportAddress() const
91e8e66c5cSPhilippe Houdoin 									{ return fTransportAddress.String(); }
92dc90a8c5SPhilippe Houdoin 
93dc90a8c5SPhilippe Houdoin 			SpoolFolder* 		Folder() const;
94dc90a8c5SPhilippe Houdoin 			BDirectory* 		Node();
95dc90a8c5SPhilippe Houdoin 			void				UpdatePendingJobs();
96dc90a8c5SPhilippe Houdoin 
97dc90a8c5SPhilippe Houdoin private:
98dc90a8c5SPhilippe Houdoin 			void				_GetStringProperty(const char* propName,
99dc90a8c5SPhilippe Houdoin 									BString& outString);
100*51c4f366SJanus 			BBitmap*			_LoadVectorIcon(const char* resourceName,
101*51c4f366SJanus 									float iconSize);
102dc90a8c5SPhilippe Houdoin 
103dc90a8c5SPhilippe Houdoin 			SpoolFolder*		fFolder;
104dc90a8c5SPhilippe Houdoin 			BDirectory			fNode;
105dc90a8c5SPhilippe Houdoin 			BString				fComments;
106dc90a8c5SPhilippe Houdoin 			BString				fTransport;
10776108fd7SPhilippe Houdoin 			BString				fTransportAddress;
108dc90a8c5SPhilippe Houdoin 			BString				fDriverName;
109dc90a8c5SPhilippe Houdoin 			BString				fName;
110dc90a8c5SPhilippe Houdoin 			BString				fPendingJobs;
111dc90a8c5SPhilippe Houdoin 			PrinterListLayoutData& fLayoutData;
112dc90a8c5SPhilippe Houdoin 
113dc90a8c5SPhilippe Houdoin 	static	BBitmap*			sIcon;
114dc90a8c5SPhilippe Houdoin 	static	BBitmap*			sSelectedIcon;
115dc90a8c5SPhilippe Houdoin };
116dc90a8c5SPhilippe Houdoin 
117dc90a8c5SPhilippe Houdoin #endif // _PRINTERS_LISTVIEW_H
118