Fixed FolderListener interface,

broken since the no-functional :-) changing r36750 : the three hooks were
renamed.
Now added/removed print spoolers show up live again.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37838 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2010-08-02 11:26:47 +00:00
parent 29145bab8a
commit 3c9765c76c
2 changed files with 51 additions and 48 deletions

View File

@ -70,7 +70,7 @@ PrinterListView::BuildPrinterList()
BDirectory printer(&entry);
_AddPrinter(printer, false);
}
_LayoutPrinterItems();
}
@ -151,6 +151,40 @@ PrinterListView::SelectedItem() const
}
// FolderListener interface
void
PrinterListView::EntryCreated(node_ref* node, entry_ref* entry)
{
BDirectory printer(node);
_AddPrinter(printer, true);
}
void
PrinterListView::EntryRemoved(node_ref* node)
{
PrinterItem* item = _FindItem(node);
if (item) {
if (item == fActivePrinter)
fActivePrinter = NULL;
RemoveItem(item);
delete item;
}
}
void
PrinterListView::AttributeChanged(node_ref* node)
{
BDirectory printer(node);
_AddPrinter(printer, true);
}
// private methods
void
PrinterListView::_AddPrinter(BDirectory& printer, bool calculateLayout)
{
@ -169,7 +203,7 @@ PrinterListView::_AddPrinter(BDirectory& printer, bool calculateLayout)
if (info.GetType(buffer) == B_OK
&& strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) {
// Yes, it is a printer definition node
AddItem(new PrinterItem(dynamic_cast<PrintersWindow*>(Window()),
AddItem(new PrinterItem(dynamic_cast<PrintersWindow*>(Window()),
printer, fLayoutData));
if (calculateLayout)
_LayoutPrinterItems();
@ -183,20 +217,20 @@ PrinterListView::_LayoutPrinterItems()
{
float& leftColumnMaximumWidth = fLayoutData.fLeftColumnMaximumWidth;
float& rightColumnMaximumWidth = fLayoutData.fRightColumnMaximumWidth;
for (int32 i = 0; i < CountItems(); i ++) {
for (int32 i = 0; i < CountItems(); i ++) {
PrinterItem* item = dynamic_cast<PrinterItem*>(ItemAt(i));
float leftColumnWidth = 0;
float rightColumnWidth = 0;
item->GetColumnWidth(this, leftColumnWidth, rightColumnWidth);
leftColumnMaximumWidth = MAX(leftColumnMaximumWidth,
leftColumnMaximumWidth = MAX(leftColumnMaximumWidth,
leftColumnWidth);
rightColumnMaximumWidth = MAX(rightColumnMaximumWidth,
rightColumnMaximumWidth = MAX(rightColumnMaximumWidth,
rightColumnWidth);
}
Invalidate();
}
@ -214,37 +248,6 @@ PrinterListView::_FindItem(node_ref* node) const
}
void
PrinterListView::_EntryCreated(node_ref* node, entry_ref* entry)
{
BDirectory printer(node);
_AddPrinter(printer, true);
}
void
PrinterListView::_EntryRemoved(node_ref* node)
{
PrinterItem* item = _FindItem(node);
if (item) {
if (item == fActivePrinter)
fActivePrinter = NULL;
RemoveItem(item);
delete item;
}
}
void
PrinterListView::_AttributeChanged(node_ref* node)
{
BDirectory printer(node);
_AddPrinter(printer, true);
}
// #pragma mark -- PrinterItem
@ -325,10 +328,10 @@ PrinterItem::GetColumnWidth(BView* view, float& leftColumn, float& rightColumn)
{
BFont font;
view->GetFont(&font);
leftColumn = font.StringWidth(fName.String());
leftColumn = MAX(leftColumn, font.StringWidth(fDriverName.String()));
rightColumn = font.StringWidth(fPendingJobs.String());
rightColumn = MAX(rightColumn, font.StringWidth(fTransport.String()));
rightColumn = MAX(rightColumn, font.StringWidth(fComments.String()));
@ -413,7 +416,7 @@ PrinterItem::DrawItem(BView *owner, BRect /*bounds*/, bool complete)
} else {
width = fLayoutData.fRightColumnMaximumWidth;
}
BPoint pendingPt(bounds.right - width - 8.0, namePt.y);
BPoint transportPt(bounds.right - width - 8.0, driverPt.y);
BPoint commentPt(bounds.right - width - 8.0, defaultPt.y);

View File

@ -47,7 +47,7 @@ public:
PrinterItem *ActivePrinter() const;
void SetActivePrinter(PrinterItem* item);
private:
typedef BListView Inherited;
@ -55,10 +55,10 @@ private:
void _LayoutPrinterItems();
PrinterItem *_FindItem(node_ref* node) const;
void _EntryCreated(node_ref *node,
void EntryCreated(node_ref *node,
entry_ref *entry);
void _EntryRemoved(node_ref *node);
void _AttributeChanged(node_ref *node);
void EntryRemoved(node_ref *node);
void AttributeChanged(node_ref *node);
FolderWatcher *fFolder;
PrinterItem *fActivePrinter;
@ -73,9 +73,9 @@ public:
PrinterListLayoutData& layoutData);
~PrinterItem();
void GetColumnWidth(BView* view, float& leftColumn,
void GetColumnWidth(BView* view, float& leftColumn,
float& rightColumn);
void DrawItem(BView *owner, BRect bounds,
bool complete);
void Update(BView *owner, const BFont *font);