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