* remove and delete listview items

* removed unmaintained fNode var from listview
* don't exit just in case we can't load the icons,
  instead draw an string what the default printer is
* call create_directory only if the printers dir does not exist



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25120 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2008-04-23 22:32:14 +00:00
parent 0babd6b999
commit ccf92546c4
2 changed files with 192 additions and 176 deletions
+164 -149
View File
@@ -1,8 +1,8 @@
/*****************************************************************************/ /*****************************************************************************/
// Printers Preference Application. // Printers Preference Application.
// //
// This application and all source files used in its construction, except // This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written // where noted, are licensed under the MIT License, and have been written
// and are: // and are:
// //
// Copyright (c) 2001-2003 OpenBeOS Project // Copyright (c) 2001-2003 OpenBeOS Project
@@ -10,18 +10,18 @@
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation // to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, // the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the // and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions: // Software is furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included // The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software. // in all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
/*****************************************************************************/ /*****************************************************************************/
@@ -41,7 +41,9 @@
#include <Mime.h> #include <Mime.h>
#include <StorageKit.h> #include <StorageKit.h>
// Implementation of PrinterListView
// #pragma mark -- PrinterListView
PrinterListView::PrinterListView(BRect frame) PrinterListView::PrinterListView(BRect frame)
: Inherited(frame, "printers_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL), : Inherited(frame, "printers_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL),
@@ -51,27 +53,29 @@ PrinterListView::PrinterListView(BRect frame)
} }
PrinterListView::~PrinterListView()
{
while (!IsEmpty())
delete RemoveItem(0L);
}
void void
PrinterListView::BuildPrinterList() PrinterListView::BuildPrinterList()
{ {
// clear list // clear list
const BListItem** items = Items(); while (!IsEmpty())
for (int32 i = CountItems()-1; i >= 0; i --) delete RemoveItem(0L);
delete items[i];
MakeEmpty();
// Find directory containing printer definition nodes // Find directory containing printer definition nodes
BPath path; BPath path;
status_t rc = ::find_directory(B_USER_PRINTERS_DIRECTORY, &path); if (find_directory(B_USER_PRINTERS_DIRECTORY, &path) != B_OK)
if (rc != B_OK)
return; return;
BDirectory dir(path.Path()); BDirectory dir(path.Path());
rc = dir.InitCheck(); if (dir.InitCheck() != B_OK)
if (rc != B_OK)
return; return;
fNode = dir;
BEntry entry; BEntry entry;
while(dir.GetNextEntry(&entry) == B_OK) { while(dir.GetNextEntry(&entry) == B_OK) {
BDirectory printer(&entry); BDirectory printer(&entry);
@@ -80,23 +84,30 @@ PrinterListView::BuildPrinterList()
} }
void void
PrinterListView::AttachedToWindow() PrinterListView::AttachedToWindow()
{ {
Inherited::AttachedToWindow(); Inherited::AttachedToWindow();
SetSelectionMessage(new BMessage(kMsgPrinterSelected)); SetSelectionMessage(new BMessage(kMsgPrinterSelected));
SetInvocationMessage(new BMessage(kMsgMakeDefaultPrinter)); SetInvocationMessage(new BMessage(kMsgMakeDefaultPrinter));
SetTarget(Window()); SetTarget(Window());
BPath path; BPath path;
bool hasPrintersDirectory = find_directory(B_USER_PRINTERS_DIRECTORY, &path) == B_OK; if (find_directory(B_USER_PRINTERS_DIRECTORY, &path) != B_OK)
return;
if (hasPrintersDirectory) {
create_directory(path.Path(), 0777); BDirectory dir(path.Path());
// directory has to exist in order to start watching it if (dir.InitCheck() != B_OK) {
// directory has to exist in order to start watching it
if (create_directory(path.Path(), 0777) != B_OK)
return;
dir.SetTo(path.Path());
} }
fFolder = new FolderWatcher(Window(), dir, true);
fFolder->SetListener(this);
BuildPrinterList(); BuildPrinterList();
// Select active printer // Select active printer
@@ -109,42 +120,34 @@ PrinterListView::AttachedToWindow()
break; break;
} }
} }
if (hasPrintersDirectory) {
BDirectory dir(path.Path());
if (dir.InitCheck() == B_OK) {
fFolder = new FolderWatcher(this->Window(), dir, true);
fFolder->SetListener(this);
}
}
} }
bool bool
PrinterListView::QuitRequested() PrinterListView::QuitRequested()
{ {
delete fFolder; fFolder = NULL; delete fFolder;
return true; return true;
} }
void void
PrinterListView::AddPrinter(BDirectory& printer) PrinterListView::AddPrinter(BDirectory& printer)
{ {
BString state; BString state;
node_ref node; node_ref node;
// If the entry is a directory // If the entry is a directory
if (printer.InitCheck() == B_OK && if (printer.InitCheck() == B_OK
printer.GetNodeRef(&node) == B_OK && && printer.GetNodeRef(&node) == B_OK
FindItem(&node) == NULL && && FindItem(&node) == NULL
printer.ReadAttrString(PSRV_PRINTER_ATTR_STATE, &state) == B_OK && && printer.ReadAttrString(PSRV_PRINTER_ATTR_STATE, &state) == B_OK
state == "free") { && state == "free") {
// Check it's Mime type for a spool director // Check it's Mime type for a spool director
BNodeInfo info(&printer); BNodeInfo info(&printer);
char buffer[256]; char buffer[256];
if (info.GetType(buffer) == B_OK && if (info.GetType(buffer) == B_OK
strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) { && strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) {
// Yes, it is a printer definition node // Yes, it is a printer definition node
AddItem(new PrinterItem(dynamic_cast<PrintersWindow*>(Window()), printer)); AddItem(new PrinterItem(dynamic_cast<PrintersWindow*>(Window()), printer));
} }
@@ -152,7 +155,8 @@ PrinterListView::AddPrinter(BDirectory& printer)
} }
PrinterItem* PrinterListView::FindItem(node_ref* node) PrinterItem*
PrinterListView::FindItem(node_ref* node) const
{ {
for (int32 i = CountItems()-1; i >= 0; i --) { for (int32 i = CountItems()-1; i >= 0; i --) {
PrinterItem* item = dynamic_cast<PrinterItem*>(ItemAt(i)); PrinterItem* item = dynamic_cast<PrinterItem*>(ItemAt(i));
@@ -165,15 +169,15 @@ PrinterItem* PrinterListView::FindItem(node_ref* node)
} }
void void
PrinterListView::EntryCreated(node_ref* node, entry_ref* entry) PrinterListView::EntryCreated(node_ref* node, entry_ref* entry)
{ {
BDirectory printer(node); BDirectory printer(node);
AddPrinter(printer); AddPrinter(printer);
} }
void PrinterListView::EntryRemoved(node_ref* node) void PrinterListView::EntryRemoved(node_ref* node)
{ {
PrinterItem* item = FindItem(node); PrinterItem* item = FindItem(node);
if (item) { if (item) {
@@ -185,24 +189,27 @@ void PrinterListView::EntryRemoved(node_ref* node)
} }
} }
void
PrinterListView::AttributeChanged(node_ref* node) void
PrinterListView::AttributeChanged(node_ref* node)
{ {
BDirectory printer(node); BDirectory printer(node);
AddPrinter(printer); AddPrinter(printer);
} }
void
void
PrinterListView::UpdateItem(PrinterItem* item) PrinterListView::UpdateItem(PrinterItem* item)
{ {
item->UpdatePendingJobs(); item->UpdatePendingJobs();
InvalidateItem(IndexOf(item)); InvalidateItem(IndexOf(item));
} }
PrinterItem* PrinterListView::SelectedItem()
PrinterItem*
PrinterListView::SelectedItem() const
{ {
BListItem* item = ItemAt(CurrentSelection()); return dynamic_cast<PrinterItem*>(ItemAt(CurrentSelection()));
return dynamic_cast<PrinterItem*>(item);
} }
@@ -220,6 +227,9 @@ PrinterListView::SetActivePrinter(PrinterItem* item)
} }
// #pragma mark -- PrinterItem
BBitmap* PrinterItem::sIcon = NULL; BBitmap* PrinterItem::sIcon = NULL;
BBitmap* PrinterItem::sSelectedIcon = NULL; BBitmap* PrinterItem::sSelectedIcon = NULL;
@@ -229,47 +239,36 @@ PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node)
fFolder(NULL), fFolder(NULL),
fNode(node) fNode(node)
{ {
BRect rect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1);
if (sIcon == NULL) { if (sIcon == NULL) {
#ifdef HAIKU_TARGET_PLATFORM_HAIKU #ifdef HAIKU_TARGET_PLATFORM_HAIKU
sIcon = new BBitmap(BRect(0,0,B_LARGE_ICON-1,B_LARGE_ICON-1), B_RGBA32); sIcon = new BBitmap(rect, B_RGBA32);
#else #else
sIcon = new BBitmap(BRect(0,0,B_LARGE_ICON-1,B_LARGE_ICON-1), B_CMAP8); sIcon = new BBitmap(rect, B_CMAP8);
#endif #endif
BMimeType type(PSRV_PRINTER_FILETYPE); BMimeType type(PSRV_PRINTER_FILETYPE);
type.GetIcon(sIcon, B_LARGE_ICON); type.GetIcon(sIcon, B_LARGE_ICON);
} }
if (sSelectedIcon == NULL) { if (sIcon && sIcon->IsValid() && sSelectedIcon == NULL) {
BBitmap *checkMark = LoadBitmap("check_mark_icon", 'BBMP'); BBitmap *checkMark = LoadBitmap("check_mark_icon", 'BBMP');
if (checkMark == NULL) { sSelectedIcon = new BBitmap(rect, B_RGBA32, true);
BAlert *alert = new BAlert("Error", if (checkMark && checkMark->IsValid()
"Fatal error: Check mark icon could not be loaded from resources!", && sSelectedIcon && sSelectedIcon->IsValid()) {
"Bye"); // draw check mark at bottom left over printer icon
alert->Go(); BView *view = new BView(rect, "offscreen", B_FOLLOW_ALL, B_WILL_DRAW);
exit(1); float y = rect.Height() - checkMark->Bounds().Height();
sSelectedIcon->Lock();
sSelectedIcon->AddChild(view);
view->DrawBitmap(sIcon);
view->SetDrawingMode(B_OP_ALPHA);
view->DrawBitmap(checkMark, BPoint(0, y));
view->Sync();
view->RemoveSelf();
sSelectedIcon->Unlock();
delete view;
delete checkMark;
} }
// draw check mark at bottom left over printer icon
sSelectedIcon = new BBitmap(sIcon->Bounds(), B_RGBA32, true);
if (!sSelectedIcon->IsValid()) {
BAlert *alert = new BAlert("Error",
"Fatal error: Bitmap could not be created for selected printer icon!",
"Bye");
alert->Go();
exit(1);
}
BView *view = new BView(sIcon->Bounds(), "offscreen", B_FOLLOW_ALL, B_WILL_DRAW);
float y = sIcon->Bounds().Height() - checkMark->Bounds().Height();
sSelectedIcon->Lock();
sSelectedIcon->AddChild(view);
view->DrawBitmap(sIcon);
view->SetDrawingMode(B_OP_ALPHA);
view->DrawBitmap(checkMark, BPoint(0, y));
view->Sync();
view->RemoveSelf();
sSelectedIcon->Unlock();
delete view;
delete checkMark;
} }
// Get Name of printer // Get Name of printer
@@ -279,56 +278,54 @@ PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node)
GetStringProperty(PSRV_PRINTER_ATTR_DRV_NAME, fDriverName); GetStringProperty(PSRV_PRINTER_ATTR_DRV_NAME, fDriverName);
BPath path; BPath path;
if (find_directory(B_USER_PRINTERS_DIRECTORY, &path) != B_OK)
return;
// Setup spool folder // Setup spool folder
if (find_directory(B_USER_PRINTERS_DIRECTORY, &path) == B_OK) { path.Append(fName.String());
path.Append(fName.String()); BDirectory dir(path.Path());
BDirectory dir(path.Path()); if (dir.InitCheck() == B_OK) {
if (dir.InitCheck() != B_OK) return;
fFolder = new SpoolFolder(window, this, dir); fFolder = new SpoolFolder(window, this, dir);
UpdatePendingJobs();
} }
UpdatePendingJobs();
} }
PrinterItem::~PrinterItem() PrinterItem::~PrinterItem()
{ {
delete fFolder; fFolder = NULL; delete fFolder;
} }
void void
PrinterItem::GetStringProperty(const char* propName, BString& outString) PrinterItem::GetStringProperty(const char* propName, BString& outString)
{ {
fNode.ReadAttrString(propName, &outString); fNode.ReadAttrString(propName, &outString);
} }
void void
PrinterItem::Update(BView *owner, const BFont *font) PrinterItem::Update(BView *owner, const BFont *font)
{ {
BListItem::Update(owner,font); BListItem::Update(owner,font);
font_height height; font_height height;
font->GetHeight(&height); font->GetHeight(&height);
SetHeight( (height.ascent+height.descent+height.leading) * 3.0 +4 ); SetHeight((height.ascent + height.descent + height.leading) * 3.0 + 8.0);
} }
bool PrinterItem::Remove(BListView* view) bool PrinterItem::Remove(BListView* view)
{ {
BMessenger msgr; BMessenger msgr;
if (GetPrinterServerMessenger(msgr) == B_OK) {
if (GetPrinterServerMessenger(msgr) == B_OK)
{
BMessage script(B_DELETE_PROPERTY); BMessage script(B_DELETE_PROPERTY);
script.AddSpecifier("Printer", view->IndexOf(this));
BMessage reply; BMessage reply;
if (msgr.SendMessage(&script,&reply) == B_OK)
script.AddSpecifier("Printer", view->IndexOf(this));
if (msgr.SendMessage(&script,&reply) == B_OK) {
return true; return true;
}
} }
return false; return false;
} }
@@ -340,82 +337,100 @@ void PrinterItem::DrawItem(BView *owner, BRect /*bounds*/, bool complete)
if (list == NULL) if (list == NULL)
return; return;
font_height height;
BFont font; BFont font;
owner->GetFont(&font); owner->GetFont(&font);
font_height height;
font.GetHeight(&height); font.GetHeight(&height);
float fntheight = height.ascent+height.descent+height.leading;
float fntheight = height.ascent + height.descent + height.leading;
BRect bounds = list->ItemFrame(list->IndexOf(this)); BRect bounds = list->ItemFrame(list->IndexOf(this));
rgb_color color = owner->ViewColor();
if ( IsSelected() )
color = tint_color(color, B_HIGHLIGHT_BACKGROUND_TINT);
rgb_color oldviewcolor = owner->ViewColor();
rgb_color oldlowcolor = owner->LowColor();
rgb_color oldcolor = owner->HighColor();
owner->SetViewColor( color );
owner->SetHighColor( color );
owner->SetLowColor( color );
owner->FillRect(bounds);
owner->SetLowColor( oldlowcolor );
owner->SetHighColor( oldcolor );
BPoint iconPt = bounds.LeftTop() + BPoint(2,2); rgb_color color = owner->ViewColor();
BPoint namePt = iconPt + BPoint(B_LARGE_ICON+8, fntheight); rgb_color oldViewColor = color;
BPoint driverPt = iconPt + BPoint(B_LARGE_ICON+8, fntheight*2); rgb_color oldLowColor = owner->LowColor();
BPoint commentPt = iconPt + BPoint(B_LARGE_ICON+8, fntheight*3); rgb_color oldHighColor = owner->HighColor();
if (IsSelected())
color = tint_color(color, B_HIGHLIGHT_BACKGROUND_TINT);
owner->SetViewColor(color);
owner->SetLowColor(color);
owner->SetHighColor(color);
owner->FillRect(bounds);
owner->SetLowColor(oldLowColor);
owner->SetHighColor(oldHighColor);
float x = B_LARGE_ICON + 8.0;
BPoint iconPt(bounds.LeftTop() + BPoint(2.0, 2.0));
BPoint namePt(iconPt + BPoint(x, fntheight));
BPoint driverPt(iconPt + BPoint(x, fntheight * 2.0));
BPoint defaultPt(iconPt + BPoint(x, fntheight * 3.0));
float width = owner->StringWidth("No pending jobs."); float width = owner->StringWidth("No pending jobs.");
BPoint pendingPt(bounds.right - width -8, namePt.y); BPoint pendingPt(bounds.right - width - 8.0, namePt.y);
BPoint transportPt(bounds.right - width -8, driverPt.y); BPoint transportPt(bounds.right - width - 8.0, driverPt.y);
BPoint commentPt(bounds.right - width - 8.0, defaultPt.y);
drawing_mode mode = owner->DrawingMode(); drawing_mode mode = owner->DrawingMode();
#ifdef HAIKU_TARGET_PLATFORM_HAIKU #ifdef HAIKU_TARGET_PLATFORM_HAIKU
owner->SetDrawingMode(B_OP_ALPHA); owner->SetDrawingMode(B_OP_ALPHA);
#else #else
owner->SetDrawingMode(B_OP_OVER); owner->SetDrawingMode(B_OP_OVER);
#endif #endif
owner->DrawBitmap(IsActivePrinter() ? sSelectedIcon : sIcon, iconPt); if (IsActivePrinter()) {
if (sSelectedIcon && sSelectedIcon->IsValid())
owner->DrawBitmap(sSelectedIcon, iconPt);
else
owner->DrawString("Default Printer", defaultPt);
} else {
if (sIcon && sIcon->IsValid())
owner->DrawBitmap(sIcon, iconPt);
}
owner->SetDrawingMode(B_OP_OVER);
// left of item // left of item
owner->DrawString(fName.String(), fName.Length(), namePt); owner->DrawString(fName.String(), fName.Length(), namePt);
owner->DrawString(fDriverName.String(), fDriverName.Length(), driverPt); owner->DrawString(fDriverName.String(), fDriverName.Length(), driverPt);
owner->DrawString(fComments.String(), fComments.Length(), commentPt);
// right of item // right of item
owner->DrawString(fPendingJobs.String(), 16, pendingPt); owner->DrawString(fPendingJobs.String(), 16, pendingPt);
owner->DrawString(fTransport.String(), fTransport.Length(), transportPt); owner->DrawString(fTransport.String(), fTransport.Length(), transportPt);
owner->DrawString(fComments.String(), fComments.Length(), commentPt);
owner->SetDrawingMode(mode);
owner->SetViewColor(oldviewcolor); owner->SetDrawingMode(mode);
owner->SetViewColor(oldViewColor);
} }
bool bool
PrinterItem::IsActivePrinter() PrinterItem::IsActivePrinter() const
{ {
return fName == ActivePrinterName(); return fName == ActivePrinterName();
} }
bool bool
PrinterItem::HasPendingJobs() PrinterItem::HasPendingJobs() const
{ {
return fFolder && fFolder->CountJobs() > 0; return fFolder && fFolder->CountJobs() > 0;
} }
SpoolFolder* PrinterItem::Folder() SpoolFolder*
PrinterItem::Folder() const
{ {
return fFolder; return fFolder;
} }
BDirectory* BDirectory*
PrinterItem::Node() PrinterItem::Node()
{ {
return &fNode; return &fNode;
} }
@@ -430,7 +445,7 @@ PrinterItem::UpdatePendingJobs()
fPendingJobs = "1 pending job."; fPendingJobs = "1 pending job.";
return; return;
} else if (pendingJobs > 1) { } else if (pendingJobs > 1) {
fPendingJobs << pendingJobs << " pending jobs.h"; fPendingJobs << pendingJobs << " pending jobs.";
return; return;
} }
} }
+28 -27
View File
@@ -1,8 +1,8 @@
/*****************************************************************************/ /*****************************************************************************/
// Printers Preference Application. // Printers Preference Application.
// //
// This application and all source files used in its construction, except // This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written // where noted, are licensed under the MIT License, and have been written
// and are: // and are:
// //
// Copyright (c) 2001-2003 OpenBeOS Project // Copyright (c) 2001-2003 OpenBeOS Project
@@ -10,18 +10,18 @@
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation // to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, // the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the // and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions: // Software is furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included // The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software. // in all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
/*****************************************************************************/ /*****************************************************************************/
@@ -46,29 +46,30 @@ class PrinterListView;
class PrinterListView : public BListView, public FolderListener { class PrinterListView : public BListView, public FolderListener {
private: private:
typedef BListView Inherited; typedef BListView Inherited;
void AddPrinter(BDirectory &printer); void AddPrinter(BDirectory &printer);
PrinterItem *FindItem(node_ref *node); PrinterItem *FindItem(node_ref *node) const;
void EntryCreated(node_ref *node, entry_ref *entry); void EntryCreated(node_ref *node, entry_ref *entry);
void EntryRemoved(node_ref *node); void EntryRemoved(node_ref *node);
void AttributeChanged(node_ref *node); void AttributeChanged(node_ref *node);
public: public:
PrinterListView(BRect frame); PrinterListView(BRect frame);
~PrinterListView();
void AttachedToWindow(); void AttachedToWindow();
bool QuitRequested(); bool QuitRequested();
void BuildPrinterList(); void BuildPrinterList();
PrinterItem *SelectedItem(); PrinterItem *SelectedItem() const;
void UpdateItem(PrinterItem *item); void UpdateItem(PrinterItem *item);
PrinterItem* ActivePrinter() const; PrinterItem* ActivePrinter() const;
void SetActivePrinter(PrinterItem* item); void SetActivePrinter(PrinterItem* item);
private: private:
BDirectory fNode; FolderWatcher *fFolder;
FolderWatcher *fFolder;
PrinterItem *fActivePrinter; PrinterItem *fActivePrinter;
}; };
@@ -78,25 +79,25 @@ class PrinterItem : public BListItem {
public: public:
PrinterItem(PrintersWindow *window, const BDirectory &node); PrinterItem(PrintersWindow *window, const BDirectory &node);
~PrinterItem(); ~PrinterItem();
void DrawItem(BView *owner, BRect bounds, bool complete); void DrawItem(BView *owner, BRect bounds, bool complete);
void Update(BView *owner, const BFont *font); void Update(BView *owner, const BFont *font);
bool Remove(BListView *view); bool Remove(BListView *view);
bool IsActivePrinter(); bool IsActivePrinter() const;
bool HasPendingJobs(); bool HasPendingJobs() const;
const char *Name() const { const char *Name() const {
return fName.String(); return fName.String();
} }
SpoolFolder *Folder(); SpoolFolder *Folder() const;
BDirectory *Node(); BDirectory *Node();
void UpdatePendingJobs(); void UpdatePendingJobs();
private: private:
void GetStringProperty(const char *propName, BString &outString); void GetStringProperty(const char *propName, BString &outString);
SpoolFolder *fFolder; SpoolFolder *fFolder;
BDirectory fNode; BDirectory fNode;
BString fComments; BString fComments;
@@ -104,7 +105,7 @@ class PrinterItem : public BListItem {
BString fDriverName; BString fDriverName;
BString fName; BString fName;
BString fPendingJobs; BString fPendingJobs;
static BBitmap *sIcon; static BBitmap *sIcon;
static BBitmap *sSelectedIcon; static BBitmap *sSelectedIcon;
}; };