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 21class SpoolFolder; 22class PrinterItem; 23class PrinterListView; 24class BBitmap; 25class PrintersWindow; 26 27 28struct PrinterListLayoutData 29{ 30 float fLeftColumnMaximumWidth; 31 float fRightColumnMaximumWidth; 32}; 33 34 35 36class PrinterListView : public BListView, public FolderListener { 37public: 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 51private: 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 69class PrinterItem : public BListItem { 70public: 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 87 const char* Name() const { return fName.String(); } 88 const char* Driver() const { return fDriverName.String(); } 89 const char* Transport() const { return fTransport.String(); } 90 const char* TransportAddress() const 91 { return fTransportAddress.String(); } 92 93 SpoolFolder* Folder() const; 94 BDirectory* Node(); 95 void UpdatePendingJobs(); 96 97private: 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