2 * Copyright 2008 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Julun, <host.haiku@gmx.de
9 #include <PrinterRoster.h>
11 #include <FindDirectory.h>
13 #include <NodeMonitor.h>
25 BPrinterRoster::BPrinterRoster()
29 find_directory(B_USER_PRINTERS_DIRECTORY
, &path
, true);
30 BNode(path
.Path()).GetNodeRef(&fUserPrintersNodRef
);
32 fUserPrintersDirectory
.SetTo(&fUserPrintersNodRef
);
36 BPrinterRoster::~BPrinterRoster()
43 BPrinterRoster::CountPrinters()
49 while (GetNextPrinter(&printer
) == B_OK
)
58 BPrinterRoster::GetNextPrinter(BPrinter
* printer
)
63 status_t status
= fUserPrintersDirectory
.InitCheck();
69 while (status
== B_OK
&& next
) {
70 status
= fUserPrintersDirectory
.GetNextEntry(&entry
);
72 printer
->SetTo(entry
);
73 next
= !printer
->IsValid();
83 BPrinterRoster::GetDefaultPrinter(BPrinter
* printer
)
88 BDirectory
dir(&fUserPrintersNodRef
);
89 status_t status
= dir
.InitCheck();
94 while (dir
.GetNextEntry(&entry
) == B_OK
) {
95 if (!entry
.IsDirectory())
98 printer
->SetTo(entry
);
99 if (printer
->IsValid() && printer
->IsDefault())
108 BPrinterRoster::FindPrinter(const BString
& name
, BPrinter
* printer
)
110 if (name
.Length() <= 0 || !printer
)
113 BDirectory
dir(&fUserPrintersNodRef
);
114 status_t status
= dir
.InitCheck();
119 while (dir
.GetNextEntry(&entry
) == B_OK
) {
120 if (!entry
.IsDirectory())
123 printer
->SetTo(entry
);
124 if (printer
->IsValid() && printer
->Name() == name
)
134 BPrinterRoster::Rewind()
136 return fUserPrintersDirectory
.Rewind();
141 BPrinterRoster::StartWatching(const BMessenger
& listener
)
145 if (!listener
.IsValid())
148 fListener
= new(std::nothrow
) BMessenger(listener
);
152 return watch_node(&fUserPrintersNodRef
, B_WATCH_DIRECTORY
, *fListener
);
157 BPrinterRoster::StopWatching()
160 stop_watching(*fListener
);
168 } // namespace BPrivate