* some code formating, no functional change

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25301 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich 2008-05-03 10:08:10 +00:00
parent ea035707b3
commit 9ec99c6e2f
2 changed files with 160 additions and 109 deletions

View File

@ -27,26 +27,32 @@
/*****************************************************************************/ /*****************************************************************************/
#include "JobListView.h" #include "JobListView.h"
#include "pr_server.h"
#include "Messages.h"
#include "Globals.h" #include "Globals.h"
#include "Jobs.h" #include "Jobs.h"
#include "Messages.h"
#include "pr_server.h"
#include "SpoolFolder.h" #include "SpoolFolder.h"
#include <Messenger.h>
#include <Bitmap.h>
#include <String.h>
#include <Alert.h> #include <Alert.h>
#include <Bitmap.h>
#include <Messenger.h>
#include <Mime.h> #include <Mime.h>
#include <Roster.h> #include <Roster.h>
// #pragma mark -- JobListView
JobListView::JobListView(BRect frame) JobListView::JobListView(BRect frame)
: Inherited(frame, "jobs_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL) : Inherited(frame, "jobs_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL)
{ {
} }
void JobListView::AttachedToWindow()
void
JobListView::AttachedToWindow()
{ {
Inherited::AttachedToWindow(); Inherited::AttachedToWindow();
@ -55,48 +61,61 @@ void JobListView::AttachedToWindow()
} }
void JobListView::SetSpoolFolder(SpoolFolder* folder) void
JobListView::SetSpoolFolder(SpoolFolder* folder)
{ {
BPath path; BPath path;
// clear list // clear list
const BListItem** items = Items(); const BListItem** items = Items();
for (int i = CountItems() - 1; i >= 0; i --) { for (int i = CountItems() - 1; i >= 0; i --) {
delete items[i]; delete items[i];
} }
MakeEmpty(); MakeEmpty();
if (folder == NULL) return;
// Find directory containing printer definition nodes if (folder == NULL)
return;
// Find directory containing printer definition nodes
for (int32 i = 0; i < folder->CountJobs(); i ++) { for (int32 i = 0; i < folder->CountJobs(); i ++) {
Job* job = folder->JobAt(i); Job* job = folder->JobAt(i);
AddJob(job); AddJob(job);
} }
} }
JobItem* JobListView::Find(Job* job)
JobItem*
JobListView::Find(Job* job)
{ {
const int32 n = CountItems(); const int32 n = CountItems();
for (int32 i = 0; i < n; i ++) { for (int32 i = 0; i < n; i ++) {
JobItem* item = dynamic_cast<JobItem*>(ItemAt(i)); JobItem* item = dynamic_cast<JobItem*>(ItemAt(i));
if (item && item->GetJob() == job) return item; if (item && item->GetJob() == job)
return item;
} }
return NULL; return NULL;
} }
JobItem* JobListView::SelectedItem() {
JobItem*
JobListView::SelectedItem()
{
BListItem* item = ItemAt(CurrentSelection()); BListItem* item = ItemAt(CurrentSelection());
return dynamic_cast<JobItem*>(item); return dynamic_cast<JobItem*>(item);
} }
void JobListView::AddJob(Job* job)
void
JobListView::AddJob(Job* job)
{ {
JobItem* item = new JobItem(job); JobItem* item = new JobItem(job);
AddItem(item); AddItem(item);
Invalidate(); Invalidate();
} }
void JobListView::RemoveJob(Job* job)
void
JobListView::RemoveJob(Job* job)
{ {
JobItem* item = Find(job); JobItem* item = Find(job);
if (item) { if (item) {
@ -106,7 +125,9 @@ void JobListView::RemoveJob(Job* job)
} }
} }
void JobListView::UpdateJob(Job* job)
void
JobListView::UpdateJob(Job* job)
{ {
JobItem* item = Find(job); JobItem* item = Find(job);
if (item) { if (item) {
@ -115,17 +136,21 @@ void JobListView::UpdateJob(Job* job)
} }
} }
void JobListView::RestartJob()
void
JobListView::RestartJob()
{ {
JobItem* item = SelectedItem(); JobItem* item = SelectedItem();
if (item && item->GetJob()->Status() == kFailed) { if (item && item->GetJob()->Status() == kFailed) {
// setting the state changes the file attribute and // setting the state changes the file attribute and
// we will receive a notification from SpoolFolder // we will receive a notification from SpoolFolder
item->GetJob()->SetStatus(kWaiting); item->GetJob()->SetStatus(kWaiting);
} }
} }
void JobListView::CancelJob()
void
JobListView::CancelJob()
{ {
JobItem* item = SelectedItem(); JobItem* item = SelectedItem();
if (item && item->GetJob()->Status() != kProcessing) { if (item && item->GetJob()->Status() != kProcessing) {
@ -135,7 +160,8 @@ void JobListView::CancelJob()
} }
// Implementation of JobItem // #pragma mark -- JobItem
JobItem::JobItem(Job* job) JobItem::JobItem(Job* job)
: BListItem(0, false) : BListItem(0, false)
@ -143,43 +169,52 @@ JobItem::JobItem(Job* job)
, fIcon(NULL) , fIcon(NULL)
{ {
fJob->Acquire(); fJob->Acquire();
Update(); Update();
} }
JobItem::~JobItem() {
JobItem::~JobItem()
{
fJob->Release(); fJob->Release();
} }
void JobItem::Update()
void
JobItem::Update()
{ {
BNode node(&fJob->EntryRef()); BNode node(&fJob->EntryRef());
if (node.InitCheck() != B_OK) return; if (node.InitCheck() != B_OK)
return;
node.ReadAttrString(PSRV_SPOOL_ATTR_DESCRIPTION, &fName); node.ReadAttrString(PSRV_SPOOL_ATTR_DESCRIPTION, &fName);
BString mimeType; BString mimeType;
node.ReadAttrString(PSRV_SPOOL_ATTR_MIMETYPE, &mimeType); node.ReadAttrString(PSRV_SPOOL_ATTR_MIMETYPE, &mimeType);
entry_ref ref; entry_ref ref;
if (fIcon == NULL && be_roster->FindApp(mimeType.String(), &ref) == B_OK) { if (fIcon == NULL && be_roster->FindApp(mimeType.String(), &ref) == B_OK) {
fIcon = new BBitmap(BRect(0,0,B_MINI_ICON-1,B_MINI_ICON-1), B_CMAP8); fIcon = new BBitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_CMAP8);
BMimeType type(mimeType.String()); BMimeType type(mimeType.String());
if (type.GetIcon(fIcon, B_MINI_ICON) != B_OK) { if (type.GetIcon(fIcon, B_MINI_ICON) != B_OK) {
delete fIcon; fIcon = NULL; delete fIcon;
fIcon = NULL;
} }
} }
fPages = "";
int32 pages; int32 pages;
fPages = ""; fSize = ""; fStatus = ""; if (node.ReadAttr(PSRV_SPOOL_ATTR_PAGECOUNT,
B_INT32_TYPE, 0, &pages, sizeof(pages)) == sizeof(pages)) {
if (node.ReadAttr(PSRV_SPOOL_ATTR_PAGECOUNT, B_INT32_TYPE, 0, &pages, sizeof(pages)) == sizeof(pages)) {
fPages << pages; fPages << pages;
if (pages > 1) fPages << " pages."; if (pages > 1)
else fPages << " page."; fPages << " pages.";
else
fPages << " page.";
} else { } else {
fPages = "??? pages."; fPages = "??? pages.";
} }
fSize = "";
off_t size; off_t size;
if (node.GetSize(&size) == B_OK) { if (node.GetSize(&size) == B_OK) {
char buffer[80]; char buffer[80];
@ -187,34 +222,47 @@ void JobItem::Update()
fSize = buffer; fSize = buffer;
} }
fStatus = "";
switch (fJob->Status()) { switch (fJob->Status()) {
case kWaiting: fStatus = "Waiting"; case kWaiting:
fStatus = "Waiting";
break; break;
case kProcessing: fStatus = "Processing";
case kProcessing:
fStatus = "Processing";
break; break;
case kFailed: fStatus = "Failed";
case kFailed:
fStatus = "Failed";
break; break;
case kCompleted: fStatus = "Completed";
case kCompleted:
fStatus = "Completed";
break; break;
default: fStatus = "Unkown status";
default:
fStatus = "Unkown status";
} }
} }
void JobItem::Update(BView *owner, const BFont *font)
void
JobItem::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) * 2.0 +4 ); SetHeight((height.ascent + height.descent + height.leading) * 2.0 + 4.0);
} }
void JobItem::DrawItem(BView *owner, BRect, bool complete)
void
JobItem::DrawItem(BView *owner, BRect, bool complete)
{ {
BListView* list = dynamic_cast<BListView*>(owner); BListView* list = dynamic_cast<BListView*>(owner);
if (list) if (list) {
{
font_height height; font_height height;
BFont font; BFont font;
owner->GetFont(&font); owner->GetFont(&font);
@ -224,44 +272,44 @@ void JobItem::DrawItem(BView *owner, BRect, bool complete)
BRect bounds = list->ItemFrame(list->IndexOf(this)); BRect bounds = list->ItemFrame(list->IndexOf(this));
rgb_color color = owner->ViewColor(); rgb_color color = owner->ViewColor();
if ( IsSelected() ) if (IsSelected())
color = tint_color(color, B_HIGHLIGHT_BACKGROUND_TINT); color = tint_color(color, B_HIGHLIGHT_BACKGROUND_TINT);
rgb_color oldviewcolor = owner->ViewColor(); rgb_color oldviewcolor = owner->ViewColor();
rgb_color oldlowcolor = owner->LowColor(); rgb_color oldlowcolor = owner->LowColor();
rgb_color oldcolor = owner->HighColor(); rgb_color oldcolor = owner->HighColor();
owner->SetViewColor( color ); owner->SetViewColor(color);
owner->SetHighColor( color ); owner->SetHighColor(color);
owner->SetLowColor( color ); owner->SetLowColor(color);
owner->FillRect(bounds); owner->FillRect(bounds);
owner->SetLowColor( oldlowcolor ); owner->SetLowColor(oldlowcolor);
owner->SetHighColor( oldcolor ); owner->SetHighColor(oldcolor);
BPoint iconPt(bounds.LeftTop() + BPoint(2, 2)); BPoint iconPt(bounds.LeftTop() + BPoint(2, 2));
BPoint leftTop(bounds.LeftTop() + BPoint(12+B_MINI_ICON, 2)); BPoint leftTop(bounds.LeftTop() + BPoint(12 + B_MINI_ICON, 2));
BPoint namePt(leftTop + BPoint(0, fntheight)); BPoint namePt(leftTop + BPoint(0, fntheight));
BPoint statusPt(leftTop + BPoint(0, fntheight*2)); BPoint statusPt(leftTop + BPoint(0, fntheight*2));
float width = owner->StringWidth(fPages.String()); float width = owner->StringWidth(fPages.String());
BPoint pagePt(bounds.RightTop() + BPoint(-width-32, fntheight)); BPoint pagePt(bounds.RightTop() + BPoint(-width - 32, fntheight));
width = owner->StringWidth(fSize.String()); width = owner->StringWidth(fSize.String());
BPoint sizePt(bounds.RightTop() + BPoint(-width-32, fntheight*2)); BPoint sizePt(bounds.RightTop() + BPoint(-width - 32, fntheight * 2));
drawing_mode mode = owner->DrawingMode(); drawing_mode mode = owner->DrawingMode();
owner->SetDrawingMode(B_OP_OVER); owner->SetDrawingMode(B_OP_OVER);
if (fIcon) owner->DrawBitmap(fIcon, iconPt); if (fIcon)
owner->DrawBitmap(fIcon, iconPt);
// left of item // left of item
owner->DrawString(fName.String(), fName.Length(), namePt); owner->DrawString(fName.String(), fName.Length(), namePt);
owner->DrawString(fStatus.String(), fStatus.Length(), statusPt); owner->DrawString(fStatus.String(), fStatus.Length(), statusPt);
// right of item // right of item
owner->DrawString(fPages.String(), fPages.Length(), pagePt); owner->DrawString(fPages.String(), fPages.Length(), pagePt);
owner->DrawString(fSize.String(), fSize.Length(), sizePt); owner->DrawString(fSize.String(), fSize.Length(), sizePt);
owner->SetDrawingMode(mode); owner->SetDrawingMode(mode);
owner->SetViewColor(oldviewcolor); owner->SetViewColor(oldviewcolor);
} }
} }

View File

@ -29,22 +29,21 @@
#ifndef JOBLISTVIEW_H #ifndef JOBLISTVIEW_H
#define JOBLISTVIEW_H #define JOBLISTVIEW_H
#include <Messenger.h>
#include <ListView.h> #include <ListView.h>
#include <ListItem.h>
#include <String.h> #include <String.h>
#include "Jobs.h"
class BBitmap;
class Job;
class JobItem; class JobItem;
class JobListView;
class SpoolFolder; class SpoolFolder;
class JobListView : public BListView class JobListView : public BListView
{ {
typedef BListView Inherited; typedef BListView Inherited;
private:
JobItem* Find(Job* job);
public: public:
JobListView(BRect frame); JobListView(BRect frame);
void AttachedToWindow(); void AttachedToWindow();
@ -58,9 +57,12 @@ public:
void RestartJob(); void RestartJob();
void CancelJob(); void CancelJob();
private:
JobItem* Find(Job* job);
}; };
class BBitmap;
class JobItem : public BListItem class JobItem : public BListItem
{ {
public: public:
@ -75,11 +77,12 @@ public:
Job* GetJob() { return fJob; } Job* GetJob() { return fJob; }
private: private:
Job* fJob;
Job* fJob; BBitmap* fIcon;
BBitmap* fIcon; BString fName;
BString fName, fPages; BString fPages;
BString fStatus, fSize; BString fStatus;
BString fSize;
}; };