* 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:
parent
ea035707b3
commit
9ec99c6e2f
@ -27,26 +27,32 @@
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "JobListView.h"
|
||||
#include "pr_server.h"
|
||||
|
||||
#include "Messages.h"
|
||||
#include "Globals.h"
|
||||
#include "Jobs.h"
|
||||
#include "Messages.h"
|
||||
#include "pr_server.h"
|
||||
#include "SpoolFolder.h"
|
||||
|
||||
#include <Messenger.h>
|
||||
#include <Bitmap.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Messenger.h>
|
||||
#include <Mime.h>
|
||||
#include <Roster.h>
|
||||
|
||||
|
||||
// #pragma mark -- JobListView
|
||||
|
||||
|
||||
JobListView::JobListView(BRect frame)
|
||||
: Inherited(frame, "jobs_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL)
|
||||
{
|
||||
}
|
||||
|
||||
void JobListView::AttachedToWindow()
|
||||
|
||||
void
|
||||
JobListView::AttachedToWindow()
|
||||
{
|
||||
Inherited::AttachedToWindow();
|
||||
|
||||
@ -55,7 +61,8 @@ void JobListView::AttachedToWindow()
|
||||
}
|
||||
|
||||
|
||||
void JobListView::SetSpoolFolder(SpoolFolder* folder)
|
||||
void
|
||||
JobListView::SetSpoolFolder(SpoolFolder* folder)
|
||||
{
|
||||
BPath path;
|
||||
|
||||
@ -65,7 +72,9 @@ void JobListView::SetSpoolFolder(SpoolFolder* folder)
|
||||
delete items[i];
|
||||
}
|
||||
MakeEmpty();
|
||||
if (folder == NULL) return;
|
||||
|
||||
if (folder == NULL)
|
||||
return;
|
||||
|
||||
// Find directory containing printer definition nodes
|
||||
for (int32 i = 0; i < folder->CountJobs(); i ++) {
|
||||
@ -74,29 +83,39 @@ void JobListView::SetSpoolFolder(SpoolFolder* folder)
|
||||
}
|
||||
}
|
||||
|
||||
JobItem* JobListView::Find(Job* job)
|
||||
|
||||
JobItem*
|
||||
JobListView::Find(Job* job)
|
||||
{
|
||||
const int32 n = CountItems();
|
||||
for (int32 i = 0; i < n; i ++) {
|
||||
JobItem* item = dynamic_cast<JobItem*>(ItemAt(i));
|
||||
if (item && item->GetJob() == job) return item;
|
||||
if (item && item->GetJob() == job)
|
||||
return item;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JobItem* JobListView::SelectedItem() {
|
||||
|
||||
JobItem*
|
||||
JobListView::SelectedItem()
|
||||
{
|
||||
BListItem* item = ItemAt(CurrentSelection());
|
||||
return dynamic_cast<JobItem*>(item);
|
||||
}
|
||||
|
||||
void JobListView::AddJob(Job* job)
|
||||
|
||||
void
|
||||
JobListView::AddJob(Job* job)
|
||||
{
|
||||
JobItem* item = new JobItem(job);
|
||||
AddItem(item);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
void JobListView::RemoveJob(Job* job)
|
||||
|
||||
void
|
||||
JobListView::RemoveJob(Job* job)
|
||||
{
|
||||
JobItem* item = Find(job);
|
||||
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);
|
||||
if (item) {
|
||||
@ -115,7 +136,9 @@ void JobListView::UpdateJob(Job* job)
|
||||
}
|
||||
}
|
||||
|
||||
void JobListView::RestartJob()
|
||||
|
||||
void
|
||||
JobListView::RestartJob()
|
||||
{
|
||||
JobItem* item = SelectedItem();
|
||||
if (item && item->GetJob()->Status() == kFailed) {
|
||||
@ -125,7 +148,9 @@ void JobListView::RestartJob()
|
||||
}
|
||||
}
|
||||
|
||||
void JobListView::CancelJob()
|
||||
|
||||
void
|
||||
JobListView::CancelJob()
|
||||
{
|
||||
JobItem* item = SelectedItem();
|
||||
if (item && item->GetJob()->Status() != kProcessing) {
|
||||
@ -135,7 +160,8 @@ void JobListView::CancelJob()
|
||||
}
|
||||
|
||||
|
||||
// Implementation of JobItem
|
||||
// #pragma mark -- JobItem
|
||||
|
||||
|
||||
JobItem::JobItem(Job* job)
|
||||
: BListItem(0, false)
|
||||
@ -143,43 +169,52 @@ JobItem::JobItem(Job* job)
|
||||
, fIcon(NULL)
|
||||
{
|
||||
fJob->Acquire();
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
JobItem::~JobItem() {
|
||||
|
||||
JobItem::~JobItem()
|
||||
{
|
||||
fJob->Release();
|
||||
}
|
||||
|
||||
void JobItem::Update()
|
||||
|
||||
void
|
||||
JobItem::Update()
|
||||
{
|
||||
BNode node(&fJob->EntryRef());
|
||||
if (node.InitCheck() != B_OK) return;
|
||||
if (node.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
node.ReadAttrString(PSRV_SPOOL_ATTR_DESCRIPTION, &fName);
|
||||
|
||||
BString mimeType;
|
||||
node.ReadAttrString(PSRV_SPOOL_ATTR_MIMETYPE, &mimeType);
|
||||
|
||||
entry_ref ref;
|
||||
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);
|
||||
BMimeType type(mimeType.String());
|
||||
if (type.GetIcon(fIcon, B_MINI_ICON) != B_OK) {
|
||||
delete fIcon; fIcon = NULL;
|
||||
delete fIcon;
|
||||
fIcon = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
fPages = "";
|
||||
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;
|
||||
if (pages > 1) fPages << " pages.";
|
||||
else fPages << " page.";
|
||||
if (pages > 1)
|
||||
fPages << " pages.";
|
||||
else
|
||||
fPages << " page.";
|
||||
} else {
|
||||
fPages = "??? pages.";
|
||||
}
|
||||
|
||||
fSize = "";
|
||||
off_t size;
|
||||
if (node.GetSize(&size) == B_OK) {
|
||||
char buffer[80];
|
||||
@ -187,34 +222,47 @@ void JobItem::Update()
|
||||
fSize = buffer;
|
||||
}
|
||||
|
||||
fStatus = "";
|
||||
switch (fJob->Status()) {
|
||||
case kWaiting: fStatus = "Waiting";
|
||||
case kWaiting:
|
||||
fStatus = "Waiting";
|
||||
break;
|
||||
case kProcessing: fStatus = "Processing";
|
||||
|
||||
case kProcessing:
|
||||
fStatus = "Processing";
|
||||
break;
|
||||
case kFailed: fStatus = "Failed";
|
||||
|
||||
case kFailed:
|
||||
fStatus = "Failed";
|
||||
break;
|
||||
case kCompleted: fStatus = "Completed";
|
||||
|
||||
case kCompleted:
|
||||
fStatus = "Completed";
|
||||
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);
|
||||
|
||||
font_height 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);
|
||||
if (list)
|
||||
{
|
||||
if (list) {
|
||||
font_height height;
|
||||
BFont font;
|
||||
owner->GetFont(&font);
|
||||
@ -250,7 +298,8 @@ void JobItem::DrawItem(BView *owner, BRect, bool complete)
|
||||
drawing_mode mode = owner->DrawingMode();
|
||||
owner->SetDrawingMode(B_OP_OVER);
|
||||
|
||||
if (fIcon) owner->DrawBitmap(fIcon, iconPt);
|
||||
if (fIcon)
|
||||
owner->DrawBitmap(fIcon, iconPt);
|
||||
|
||||
// left of item
|
||||
owner->DrawString(fName.String(), fName.Length(), namePt);
|
||||
@ -261,7 +310,6 @@ void JobItem::DrawItem(BView *owner, BRect, bool complete)
|
||||
owner->DrawString(fSize.String(), fSize.Length(), sizePt);
|
||||
|
||||
owner->SetDrawingMode(mode);
|
||||
|
||||
owner->SetViewColor(oldviewcolor);
|
||||
}
|
||||
}
|
||||
|
@ -29,22 +29,21 @@
|
||||
#ifndef JOBLISTVIEW_H
|
||||
#define JOBLISTVIEW_H
|
||||
|
||||
#include <Messenger.h>
|
||||
|
||||
#include <ListView.h>
|
||||
#include <ListItem.h>
|
||||
#include <String.h>
|
||||
|
||||
#include "Jobs.h"
|
||||
|
||||
class BBitmap;
|
||||
class Job;
|
||||
class JobItem;
|
||||
class JobListView;
|
||||
class SpoolFolder;
|
||||
|
||||
|
||||
class JobListView : public BListView
|
||||
{
|
||||
typedef BListView Inherited;
|
||||
private:
|
||||
JobItem* Find(Job* job);
|
||||
|
||||
public:
|
||||
JobListView(BRect frame);
|
||||
void AttachedToWindow();
|
||||
@ -58,9 +57,12 @@ public:
|
||||
|
||||
void RestartJob();
|
||||
void CancelJob();
|
||||
|
||||
private:
|
||||
JobItem* Find(Job* job);
|
||||
};
|
||||
|
||||
class BBitmap;
|
||||
|
||||
class JobItem : public BListItem
|
||||
{
|
||||
public:
|
||||
@ -75,11 +77,12 @@ public:
|
||||
Job* GetJob() { return fJob; }
|
||||
|
||||
private:
|
||||
|
||||
Job* fJob;
|
||||
BBitmap* fIcon;
|
||||
BString fName, fPages;
|
||||
BString fStatus, fSize;
|
||||
BString fName;
|
||||
BString fPages;
|
||||
BString fStatus;
|
||||
BString fSize;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user