style cleanup, no functional changes

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36750 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2010-05-08 17:58:11 +00:00
parent 7d8c577325
commit 9ac4c6e861
15 changed files with 540 additions and 753 deletions
+50 -49
View File
@@ -9,30 +9,25 @@
#include "AddPrinterDialog.h"
#include "PrinterListView.h"
#include "pr_server.h"
#include "Globals.h"
#include "Messages.h"
#include <Box.h>
#include <stdio.h>
#include <Button.h>
#include <Catalog.h>
#include <TextControl.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <StringView.h>
#include <ListView.h>
#include <ScrollView.h>
#include <Application.h>
#include <StorageKit.h>
#include <Layout.h>
#include <FindDirectory.h>
#include <GridLayout.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Layout.h>
#include <NodeInfo.h>
#include <Path.h>
#include <stdio.h>
#include "pr_server.h"
#include "Globals.h"
#include "Messages.h"
#include "PrinterListView.h"
#undef B_TRANSLATE_CONTEXT
@@ -41,12 +36,12 @@
AddPrinterDialog::AddPrinterDialog(BWindow *parent)
:
Inherited(BRect(78.0, 71.0, 400, 300), B_TRANSLATE("Add printer"),
Inherited(BRect(78, 71, 400, 300), B_TRANSLATE("Add printer"),
B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
fPrintersPrefletMessenger(parent)
{
BuildGUI(0);
_BuildGUI(0);
Show();
}
@@ -65,7 +60,7 @@ AddPrinterDialog::MessageReceived(BMessage* msg)
{
switch(msg->what) {
case B_OK:
AddPrinter(msg);
_AddPrinter(msg);
PostMessage(B_QUIT_REQUESTED);
break;
@@ -75,18 +70,17 @@ AddPrinterDialog::MessageReceived(BMessage* msg)
case kNameChangedMsg:
fNameText = fName->Text();
Update();
_Update();
break;
case kPrinterSelectedMsg:
StorePrinter(msg);
_StorePrinter(msg);
break;
case kTransportSelectedMsg:
HandleChangedTransport(msg);
_HandleChangedTransport(msg);
break;
default:
Inherited::MessageReceived(msg);
}
@@ -94,7 +88,7 @@ AddPrinterDialog::MessageReceived(BMessage* msg)
void
AddPrinterDialog::AddPrinter(BMessage *msg)
AddPrinterDialog::_AddPrinter(BMessage *msg)
{
BMessage m(PSRV_MAKE_PRINTER);
BMessenger msgr;
@@ -120,19 +114,19 @@ AddPrinterDialog::AddPrinter(BMessage *msg)
void
AddPrinterDialog::StorePrinter(BMessage *msg)
AddPrinterDialog::_StorePrinter(BMessage *msg)
{
BString name;
if (msg->FindString("name", &name) != B_OK)
name = "";
fPrinterText = name;
Update();
_Update();
}
void
AddPrinterDialog::HandleChangedTransport(BMessage *msg)
AddPrinterDialog::_HandleChangedTransport(BMessage *msg)
{
BString name;
if (msg->FindString("name", &name) != B_OK) {
@@ -165,7 +159,7 @@ AddPrinterDialog::HandleChangedTransport(BMessage *msg)
fTransportPathText = "";
// remove mark from item in sub menu of transport sub menu
for (int32 i = fTransport->CountItems()-1; i >= 0; i --) {
for (int32 i = fTransport->CountItems() - 1; i >= 0; i --) {
BMenu* menu = fTransport->SubmenuAt(i);
if (menu != NULL) {
BMenuItem* item = menu->FindMarked();
@@ -174,12 +168,12 @@ AddPrinterDialog::HandleChangedTransport(BMessage *msg)
}
}
}
Update();
_Update();
}
void
AddPrinterDialog::BuildGUI(int stage)
AddPrinterDialog::_BuildGUI(int stage)
{
// add a "printer name" input field
fName = new BTextControl("printer_name", B_TRANSLATE("Printer name:"),
@@ -193,21 +187,22 @@ AddPrinterDialog::BuildGUI(int stage)
BMenuField *printerMenuField = new BMenuField("drivers_list",
B_TRANSLATE("Printer type:"), fPrinter);
printerMenuField->SetAlignment(B_ALIGN_RIGHT);
FillMenu(fPrinter, "Print", kPrinterSelectedMsg);
_FillMenu(fPrinter, "Print", kPrinterSelectedMsg);
// add a "connected to" (aka transports list) menu field
fTransport = new BPopUpMenu(B_TRANSLATE("<pick one>"));
BMenuField *transportMenuField = new BMenuField("transports_list",
B_TRANSLATE("Connected to:"), fTransport);
transportMenuField->SetAlignment(B_ALIGN_RIGHT);
FillTransportMenu(fTransport);
_FillTransportMenu(fTransport);
// add a "OK" button
fOk = new BButton(NULL, B_TRANSLATE("Add"), new BMessage((uint32)B_OK),
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
// add a "Cancel button
BButton *cancel = new BButton(NULL, B_TRANSLATE("Cancel"), new BMessage(B_CANCEL));
BButton *cancel = new BButton(NULL, B_TRANSLATE("Cancel"),
new BMessage(B_CANCEL));
SetLayout(new BGridLayout());
@@ -231,7 +226,7 @@ AddPrinterDialog::BuildGUI(int stage)
fName->MakeFocus(true);
Update();
_Update();
// Stage == 0
// init_icon 64x114 Add a Local or Network Printer
// ------------------------------
@@ -285,16 +280,18 @@ AddPrinterDialog::BuildGUI(int stage)
// Cancel Add
}
static directory_which gAddonDirs[] = {
B_BEOS_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY
};
void
AddPrinterDialog::FillMenu(BMenu* menu, const char* path, uint32 what)
AddPrinterDialog::_FillMenu(BMenu* menu, const char* path, uint32 what)
{
for (uint32 i = 0; i < sizeof(gAddonDirs) / sizeof(directory_which); i ++) {
for (uint32 i = 0; i < sizeof(gAddonDirs) / sizeof(directory_which); i++) {
BPath addonPath;
if (find_directory(gAddonDirs[i], &addonPath) != B_OK)
continue;
@@ -335,16 +332,18 @@ AddPrinterDialog::FillMenu(BMenu* menu, const char* path, uint32 what)
}
}
void AddPrinterDialog::FillTransportMenu(BMenu* menu)
void
AddPrinterDialog::_FillTransportMenu(BMenu* menu)
{
BMessenger msgr;
if (GetPrinterServerMessenger(msgr) != B_OK)
return;
for (long idx=0; ; idx++) {
for (long idx = 0; ; idx++) {
BMessage reply, msg(B_GET_PROPERTY);
msg.AddSpecifier("Transport", idx);
if (msgr.SendMessage(&msg,&reply) != B_OK)
if (msgr.SendMessage(&msg, &reply) != B_OK)
break;
BMessenger transport;
@@ -355,11 +354,11 @@ void AddPrinterDialog::FillTransportMenu(BMenu* menu)
msg.MakeEmpty();
msg.what = B_GET_PROPERTY;
msg.AddSpecifier("Name");
if (transport.SendMessage(&msg,&reply) != B_OK)
if (transport.SendMessage(&msg, &reply) != B_OK)
continue;
BString transportName;
if (reply.FindString("result",&transportName) != B_OK)
if (reply.FindString("result", &transportName) != B_OK)
continue;
// Now get ports...
@@ -367,7 +366,7 @@ void AddPrinterDialog::FillTransportMenu(BMenu* menu)
msg.MakeEmpty();
msg.what = B_GET_PROPERTY;
msg.AddSpecifier("Ports");
if (transport.SendMessage(&msg,&reply) != B_OK ||
if (transport.SendMessage(&msg, &reply) != B_OK ||
reply.FindString("port_id", &portId) != B_OK) {
// Can't find ports; so just show transport item, no menu
BMessage* menuMsg = new BMessage(kTransportSelectedMsg);
@@ -383,9 +382,10 @@ void AddPrinterDialog::FillTransportMenu(BMenu* menu)
menu->ItemAt(menu->IndexOf(transportMenu))->
SetMessage(new BMessage(kTransportSelectedMsg));
for (int32 pidx=0; reply.FindString("port_id", pidx, &portId) == B_OK; pidx++) {
if (reply.FindString("port_name", pidx, &portName) != B_OK ||
!portName.Length())
for (int32 i = 0; reply.FindString("port_id", i, &portId) == B_OK;
i++) {
if (reply.FindString("port_name", i, &portName) != B_OK
|| !portName.Length())
portName = portId;
// Create menu item in submenu for port
@@ -397,11 +397,12 @@ void AddPrinterDialog::FillTransportMenu(BMenu* menu)
}
}
void
AddPrinterDialog::Update()
AddPrinterDialog::_Update()
{
fOk->SetEnabled(fNameText != "" && fPrinterText != "" &&
(fTransportText != "" || fPrinterText == "Preview"));
fOk->SetEnabled(fNameText != "" && fPrinterText != ""
&& (fTransportText != "" || fPrinterText == "Preview"));
fTransport->SetEnabled(fPrinterText != "Preview");
}
+42 -43
View File
@@ -6,57 +6,56 @@
* Philippe Houdoin
* Michael Pfeiffer
*/
#ifndef _ADD_PRINTER_DIALOG_H
#define _ADD_PRINTER_DIALOG_H
#ifndef ADD_PRINTER_DIALOG_H
#define ADD_PRINTER_DIALOG_H
class AddPrinterDialog;
#include <Button.h>
#include <String.h>
#include <TextControl.h>
#include <PopUpMenu.h>
#include <TextControl.h>
#include <Window.h>
class AddPrinterDialog : public BWindow
{
typedef BWindow Inherited;
public:
AddPrinterDialog(BWindow *parent);
bool QuitRequested();
private:
enum MessageKind {
kPrinterSelectedMsg = 'adlg',
kTransportSelectedMsg,
kNameChangedMsg,
};
void MessageReceived(BMessage *msg);
void AddPrinter(BMessage *msg);
void StorePrinter(BMessage *msg);
void HandleChangedTransport(BMessage *msg);
void BuildGUI(int stage);
void FillTransportMenu(BMenu *menu);
void FillMenu(BMenu *menu, const char *path, uint32 what);
void AddPortSubMenu(BMenu *menu, const char *transport, const char *port);
void Update();
BMessenger fPrintersPrefletMessenger;
BTextControl *fName;
BPopUpMenu *fPrinter;
BPopUpMenu *fTransport;
BButton *fOk;
class AddPrinterDialog : public BWindow {
typedef BWindow Inherited;
public:
AddPrinterDialog(BWindow *parent);
BString fNameText;
BString fPrinterText;
BString fTransportText;
BString fTransportPathText;
void MessageReceived(BMessage *msg);
bool QuitRequested();
private:
enum MessageKind {
kPrinterSelectedMsg = 'adlg',
kTransportSelectedMsg,
kNameChangedMsg,
};
void _AddPrinter(BMessage *msg);
void _StorePrinter(BMessage *msg);
void _HandleChangedTransport(BMessage *msg);
void _BuildGUI(int stage);
void _FillTransportMenu(BMenu *menu);
void _FillMenu(BMenu *menu, const char *path,
uint32 what);
void _AddPortSubMenu(BMenu *menu,
const char *transport, const char *port);
void _Update();
BMessenger fPrintersPrefletMessenger;
BTextControl* fName;
BPopUpMenu* fPrinter;
BPopUpMenu* fTransport;
BButton* fOk;
BString fNameText;
BString fPrinterText;
BString fTransportText;
BString fTransportPathText;
};
#endif
#endif // _ADD_PRINTER_DIALOG_H
+12 -30
View File
@@ -1,37 +1,20 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#include "Globals.h"
#include "pr_server.h"
#include <stdio.h>
#include <Roster.h>
#include <stdio.h>
#include "pr_server.h"
BString
ActivePrinterName()
@@ -63,4 +46,3 @@ GetPrinterServerMessenger(BMessenger& msgr)
msgr = BMessenger(PSRV_SIGNATURE_TYPE);
return msgr.IsValid() ? B_OK : B_ERROR;
}
+10 -29
View File
@@ -1,39 +1,20 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#ifndef GLOBALS_H
#define GLOBALS_H
#include <Messenger.h>
#include <String.h>
BString ActivePrinterName();
status_t GetPrinterServerMessenger(BMessenger& msgr);
#endif
#endif // GLOBALS_H
+24 -43
View File
@@ -1,48 +1,27 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#include "JobListView.h"
#include <stdio.h>
#include <Catalog.h>
#include <MimeType.h>
#include <Roster.h>
#include <Window.h>
#include "pr_server.h"
#include "Globals.h"
#include "Jobs.h"
#include "Messages.h"
#include "pr_server.h"
#include "SpoolFolder.h"
#include <stdio.h>
#include <Alert.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <Messenger.h>
#include <Mime.h>
#include <Roster.h>
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "JobListView"
@@ -52,7 +31,8 @@
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,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE)
{
}
@@ -169,9 +149,10 @@ JobListView::CancelJob()
JobItem::JobItem(Job* job)
: BListItem(0, false)
, fJob(job)
, fIcon(NULL)
:
BListItem(0, false),
fJob(job),
fIcon(NULL)
{
fJob->Acquire();
Update();
@@ -204,10 +185,10 @@ JobItem::Update()
be_plain_font->GetHeight(&fontHeight);
float height = (fontHeight.ascent + fontHeight.descent
+ fontHeight.leading) * 2.0;
BRect rect(0.0, 0.0, height, height);
BRect rect(0, 0, height, height);
fIcon = new BBitmap(rect, B_RGBA32);
#else
BRect rect(0.0, 0.0, B_MINI_ICON - 1, B_MINI_ICON - 1);
BRect rect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1);
fIcon = new BBitmap(rect, B_CMAP8);
#endif
BMimeType type(mimeType.String());
+38 -61
View File
@@ -1,91 +1,68 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#ifndef JOBLISTVIEW_H
#define JOBLISTVIEW_H
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#ifndef _JOB_LISTVIEW_H
#define _JOB_LISTVIEW_H
#include <ListView.h>
#include <Bitmap.h>
#include <ListItem.h>
#include <ListView.h>
#include <String.h>
class BBitmap;
class Job;
class JobItem;
class SpoolFolder;
class JobListView : public BListView
{
class JobListView : public BListView {
typedef BListView Inherited;
public:
JobListView(BRect frame);
~JobListView();
JobListView(BRect frame);
~JobListView();
void AttachedToWindow();
void SetSpoolFolder(SpoolFolder* folder);
void AttachedToWindow();
void SetSpoolFolder(SpoolFolder* folder);
void AddJob(Job* job);
void RemoveJob(Job* job);
void UpdateJob(Job* job);
void AddJob(Job* job);
void RemoveJob(Job* job);
void UpdateJob(Job* job);
JobItem* SelectedItem() const;
JobItem* SelectedItem() const;
void RestartJob();
void CancelJob();
void RestartJob();
void CancelJob();
private:
JobItem* FindJob(Job* job) const;
JobItem* FindJob(Job* job) const;
};
class JobItem : public BListItem
{
class JobItem : public BListItem {
public:
JobItem(Job* job);
~JobItem();
JobItem(Job* job);
~JobItem();
void Update();
void Update();
void Update(BView *owner, const BFont *font);
void DrawItem(BView *owner, BRect bounds, bool complete);
void Update(BView *owner, const BFont *font);
void DrawItem(BView *owner, BRect bounds,
bool complete);
Job* GetJob() const { return fJob; }
Job* GetJob() const { return fJob; }
private:
Job* fJob;
BBitmap* fIcon;
BString fName;
BString fPages;
BString fStatus;
BString fSize;
Job* fJob;
BBitmap* fIcon;
BString fName;
BString fPages;
BString fStatus;
BString fSize;
};
#endif
#endif // _JOB_LISTVIEW_H
+5 -4
View File
@@ -6,12 +6,13 @@
* Michael Pfeiffer
* Philippe Houdoin
*/
#ifndef MESSAGES_H
#define MESSAGES_H
#ifndef _MESSAGES_H
#define _MESSAGES_H
#include <SupportDefs.h>
const uint32 kMsgAddPrinter = 'AddP';
const uint32 kMsgAddPrinterClosed = 'APCl';
const uint32 kMsgRemovePrinter = 'RemP';
@@ -21,4 +22,4 @@ const uint32 kMsgCancelJob = 'CncJ';
const uint32 kMsgRestartJob = 'RstJ';
const uint32 kMsgJobSelected = 'JSel';
#endif
#endif // _MESSAGES_H
+74 -89
View File
@@ -1,47 +1,27 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#include "PrinterListView.h"
#include "pr_server.h"
#include <Bitmap.h>
#include <Catalog.h>
#include <Directory.h>
#include <Mime.h>
#include <NodeInfo.h>
#include <String.h>
#include "pr_server.h"
#include "Messages.h"
#include "Globals.h"
#include "PrintersWindow.h"
#include "SpoolFolder.h"
#include <Messenger.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <String.h>
#include <Alert.h>
#include <Mime.h>
#include <StorageKit.h>
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "PrinterListView"
@@ -85,7 +65,7 @@ PrinterListView::BuildPrinterList()
BEntry entry;
while(dir.GetNextEntry(&entry) == B_OK) {
BDirectory printer(&entry);
AddPrinter(printer);
_AddPrinter(printer);
}
}
@@ -138,14 +118,43 @@ PrinterListView::QuitRequested()
void
PrinterListView::AddPrinter(BDirectory& printer)
PrinterListView::UpdateItem(PrinterItem* item)
{
item->UpdatePendingJobs();
InvalidateItem(IndexOf(item));
}
PrinterItem*
PrinterListView::ActivePrinter() const
{
return fActivePrinter;
}
void
PrinterListView::SetActivePrinter(PrinterItem* item)
{
fActivePrinter = item;
}
PrinterItem*
PrinterListView::SelectedItem() const
{
return dynamic_cast<PrinterItem*>(ItemAt(CurrentSelection()));
}
void
PrinterListView::_AddPrinter(BDirectory& printer)
{
BString state;
node_ref node;
// If the entry is a directory
if (printer.InitCheck() == B_OK
&& printer.GetNodeRef(&node) == B_OK
&& FindItem(&node) == NULL
&& _FindItem(&node) == NULL
&& printer.ReadAttrString(PSRV_PRINTER_ATTR_STATE, &state) == B_OK
&& state == "free") {
// Check it's Mime type for a spool director
@@ -162,30 +171,30 @@ PrinterListView::AddPrinter(BDirectory& printer)
PrinterItem*
PrinterListView::FindItem(node_ref* node) const
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));
node_ref ref;
if (item && item->Node()->GetNodeRef(&ref) == B_OK && ref == *node) {
if (item && item->Node()->GetNodeRef(&ref) == B_OK && ref == *node)
return item;
}
}
return NULL;
}
void
PrinterListView::EntryCreated(node_ref* node, entry_ref* entry)
PrinterListView::_EntryCreated(node_ref* node, entry_ref* entry)
{
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 == fActivePrinter)
fActivePrinter = NULL;
@@ -197,40 +206,13 @@ void PrinterListView::EntryRemoved(node_ref* node)
void
PrinterListView::AttributeChanged(node_ref* node)
PrinterListView::_AttributeChanged(node_ref* node)
{
BDirectory printer(node);
AddPrinter(printer);
_AddPrinter(printer);
}
void
PrinterListView::UpdateItem(PrinterItem* item)
{
item->UpdatePendingJobs();
InvalidateItem(IndexOf(item));
}
PrinterItem*
PrinterListView::SelectedItem() const
{
return dynamic_cast<PrinterItem*>(ItemAt(CurrentSelection()));
}
PrinterItem*
PrinterListView::ActivePrinter() const
{
return fActivePrinter;
}
void
PrinterListView::SetActivePrinter(PrinterItem* item)
{
fActivePrinter = item;
}
// #pragma mark -- PrinterItem
@@ -262,7 +244,8 @@ PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node)
sSelectedIcon = new BBitmap(rect, B_RGBA32, true);
if (sSelectedIcon && sSelectedIcon->IsValid()) {
// draw check mark at bottom left over printer icon
BView *view = new BView(rect, "offscreen", B_FOLLOW_ALL, B_WILL_DRAW);
BView *view = new BView(rect, "offscreen", B_FOLLOW_ALL,
B_WILL_DRAW);
float y = rect.Height() - checkMark->Bounds().Height();
sSelectedIcon->Lock();
sSelectedIcon->AddChild(view);
@@ -279,10 +262,10 @@ PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node)
}
// Get Name of printer
GetStringProperty(PSRV_PRINTER_ATTR_PRT_NAME, fName);
GetStringProperty(PSRV_PRINTER_ATTR_COMMENTS, fComments);
GetStringProperty(PSRV_PRINTER_ATTR_TRANSPORT, fTransport);
GetStringProperty(PSRV_PRINTER_ATTR_DRV_NAME, fDriverName);
_GetStringProperty(PSRV_PRINTER_ATTR_PRT_NAME, fName);
_GetStringProperty(PSRV_PRINTER_ATTR_COMMENTS, fComments);
_GetStringProperty(PSRV_PRINTER_ATTR_TRANSPORT, fTransport);
_GetStringProperty(PSRV_PRINTER_ATTR_DRV_NAME, fDriverName);
BPath path;
if (find_directory(B_USER_PRINTERS_DIRECTORY, &path) != B_OK)
@@ -304,13 +287,6 @@ PrinterItem::~PrinterItem()
}
void
PrinterItem::GetStringProperty(const char* propName, BString& outString)
{
fNode.ReadAttrString(propName, &outString);
}
void
PrinterItem::Update(BView *owner, const BFont *font)
{
@@ -338,7 +314,8 @@ bool PrinterItem::Remove(BListView* view)
}
void PrinterItem::DrawItem(BView *owner, BRect /*bounds*/, bool complete)
void
PrinterItem::DrawItem(BView *owner, BRect /*bounds*/, bool complete)
{
BListView* list = dynamic_cast<BListView*>(owner);
if (list == NULL)
@@ -468,3 +445,11 @@ PrinterItem::UpdatePendingJobs()
}
fPendingJobs = B_TRANSLATE("No pending jobs.");
}
void
PrinterItem::_GetStringProperty(const char* propName, BString& outString)
{
fNode.ReadAttrString(propName, &outString);
}
+73 -91
View File
@@ -1,113 +1,95 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#ifndef _PRINTERS_LISTVIEW_H
#define _PRINTERS_LISTVIEW_H
#ifndef PRINTERSLISTVIEW_H
#define PRINTERSLISTVIEW_H
class PrinterListView;
#include <Directory.h>
#include <Entry.h>
#include <Messenger.h>
#include <ListView.h>
#include <String.h>
#include <Directory.h>
#include <Entry.h>
#include "FolderWatcher.h"
class SpoolFolder;
class PrinterItem;
class PrinterListView;
class PrinterListView : public BListView, public FolderListener {
private:
typedef BListView Inherited;
void AddPrinter(BDirectory &printer);
PrinterItem *FindItem(node_ref *node) const;
void EntryCreated(node_ref *node, entry_ref *entry);
void EntryRemoved(node_ref *node);
void AttributeChanged(node_ref *node);
public:
PrinterListView(BRect frame);
~PrinterListView();
void AttachedToWindow();
bool QuitRequested();
void BuildPrinterList();
PrinterItem *SelectedItem() const;
void UpdateItem(PrinterItem *item);
PrinterItem* ActivePrinter() const;
void SetActivePrinter(PrinterItem* item);
private:
FolderWatcher *fFolder;
PrinterItem *fActivePrinter;
};
class BBitmap;
class PrintersWindow;
class PrinterItem : public BListItem {
public:
PrinterItem(PrintersWindow *window, const BDirectory &node);
~PrinterItem();
void DrawItem(BView *owner, BRect bounds, bool complete);
void Update(BView *owner, const BFont *font);
bool Remove(BListView *view);
bool IsActivePrinter() const;
bool HasPendingJobs() const;
class PrinterListView : public BListView, public FolderListener {
public:
PrinterListView(BRect frame);
~PrinterListView();
const char *Name() const {
return fName.String();
}
void AttachedToWindow();
bool QuitRequested();
SpoolFolder *Folder() const;
BDirectory *Node();
void UpdatePendingJobs();
void BuildPrinterList();
PrinterItem *SelectedItem() const;
void UpdateItem(PrinterItem *item);
private:
void GetStringProperty(const char *propName, BString &outString);
PrinterItem *ActivePrinter() const;
void SetActivePrinter(PrinterItem* item);
SpoolFolder *fFolder;
BDirectory fNode;
BString fComments;
BString fTransport;
BString fDriverName;
BString fName;
BString fPendingJobs;
private:
typedef BListView Inherited;
static BBitmap *sIcon;
static BBitmap *sSelectedIcon;
void _AddPrinter(BDirectory &printer);
PrinterItem *_FindItem(node_ref* node) const;
void _EntryCreated(node_ref *node,
entry_ref *entry);
void _EntryRemoved(node_ref *node);
void _AttributeChanged(node_ref *node);
FolderWatcher *fFolder;
PrinterItem *fActivePrinter;
};
#endif
class PrinterItem : public BListItem {
public:
PrinterItem(PrintersWindow *window,
const BDirectory &node);
~PrinterItem();
void DrawItem(BView *owner, BRect bounds,
bool complete);
void Update(BView *owner, const BFont *font);
bool Remove(BListView *view);
bool IsActivePrinter() const;
bool HasPendingJobs() const;
const char *Name() const { return fName.String(); }
SpoolFolder *Folder() const;
BDirectory *Node();
void UpdatePendingJobs();
private:
void _GetStringProperty(const char *propName,
BString &outString);
SpoolFolder *fFolder;
BDirectory fNode;
BString fComments;
BString fTransport;
BString fDriverName;
BString fName;
BString fPendingJobs;
static BBitmap *sIcon;
static BBitmap *sSelectedIcon;
};
#endif // _PRINTERS_LISTVIEW_H
+22 -33
View File
@@ -1,59 +1,48 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#include "Printers.h"
#include <Locale.h>
#include "pr_server.h"
#include "Messages.h"
#include "PrintersWindow.h"
#include <Locale.h>
int main()
int
main()
{
PrintersApp app;
app.Run();
return 0;
}
PrintersApp::PrintersApp()
: Inherited(PRINTERS_SIGNATURE)
{
be_locale->GetAppCatalog(&fCatalog);
}
void PrintersApp::ReadyToRun()
void
PrintersApp::ReadyToRun()
{
PrintersWindow* win = new PrintersWindow(BRect(78.0, 71.0, 561.0, 409.0));
PrintersWindow* win = new PrintersWindow(BRect(78, 71, 561, 409));
win->Show();
}
void PrintersApp::MessageReceived(BMessage* msg) {
void
PrintersApp::MessageReceived(BMessage* msg)
{
if (msg->what == B_PRINTER_CHANGED || msg->what == PRINTERS_ADD_PRINTER) {
// broadcast message
uint32 what = msg->what;
@@ -61,7 +50,7 @@ void PrintersApp::MessageReceived(BMessage* msg) {
what = kMsgAddPrinter;
BWindow* w;
for (int32 i = 0; (w = WindowAt(i)) != NULL; i ++) {
for (int32 i = 0; (w = WindowAt(i)) != NULL; i++) {
BMessenger msgr(NULL, w);
msgr.SendMessage(what);
}
+18 -39
View File
@@ -1,51 +1,30 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#ifndef _PRINTERS_H
#define _PRINTERS_H
#ifndef PRINTERS_H
#define PRINTERS_H
class PrintersApp;
#include <Application.h>
#include <Catalog.h>
#define PRINTERS_SIGNATURE "application/x-vnd.Be-PRNT"
class PrintersApp : public BApplication
{
typedef BApplication Inherited;
class PrintersApp : public BApplication {
typedef BApplication Inherited;
public:
PrintersApp();
void ReadyToRun();
void MessageReceived(BMessage* msg);
PrintersApp();
void ReadyToRun();
void MessageReceived(BMessage* msg);
private:
BCatalog fCatalog;
BCatalog fCatalog;
};
#endif
#endif // _PRINTERS_H
+112 -123
View File
@@ -1,49 +1,29 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#include "PrintersWindow.h"
#include "AddPrinterDialog.h"
#include "PrinterListView.h"
#include "pr_server.h"
#include "Globals.h"
#include "Messages.h"
#include "JobListView.h"
#include "SpoolFolder.h"
// BeOS API
#include <Box.h>
#include <Application.h>
#include <Button.h>
#include <Catalog.h>
#include <FindDirectory.h>
#include <ListView.h>
#include <ScrollView.h>
#include <Application.h>
#include <FindDirectory.h>
#include "pr_server.h"
#include "AddPrinterDialog.h"
#include "Globals.h"
#include "JobListView.h"
#include "Messages.h"
#include "PrinterListView.h"
#include "SpoolFolder.h"
#undef B_TRANSLATE_CONTEXT
@@ -52,8 +32,8 @@
PrintersWindow::PrintersWindow(BRect frame)
:
Inherited(BRect(78.0, 71.0, 561.0, 409.0), B_TRANSLATE("Printers"),
B_TITLED_WINDOW, 0),
Inherited(BRect(78, 71, 561, 409), B_TRANSLATE("Printers"), B_TITLED_WINDOW,
0),
fSelectedPrinter(NULL),
fAddingPrinter(false)
{
@@ -65,9 +45,8 @@ bool
PrintersWindow::QuitRequested()
{
bool result = Inherited::QuitRequested();
if (result) {
if (result)
be_app->PostMessage(B_QUIT_REQUESTED);
}
return result;
}
@@ -76,33 +55,29 @@ PrintersWindow::QuitRequested()
void
PrintersWindow::MessageReceived(BMessage* msg)
{
switch(msg->what)
{
switch(msg->what) {
case kMsgPrinterSelected:
{
fSelectedPrinter = fPrinterListView->SelectedItem();
if (fSelectedPrinter)
{
fJobsBox->SetLabel((BString(B_TRANSLATE("Print jobs for ")) <<
fSelectedPrinter->Name()).String());
fMakeDefault->SetEnabled(true);
fRemove->SetEnabled(true);
fJobListView->SetSpoolFolder(fSelectedPrinter->Folder());
}
else
{
fJobsBox->SetLabel(
B_TRANSLATE("Print jobs: No printer selected"));
fMakeDefault->SetEnabled(false);
fRemove->SetEnabled(false);
fSelectedPrinter = NULL;
fJobListView->SetSpoolFolder(NULL);
}
UpdateJobButtons();
UpdatePrinterButtons();
{
fSelectedPrinter = fPrinterListView->SelectedItem();
if (fSelectedPrinter) {
fJobsBox->SetLabel((BString(B_TRANSLATE("Print jobs for "))
<< fSelectedPrinter->Name()).String());
fMakeDefault->SetEnabled(true);
fRemove->SetEnabled(true);
fJobListView->SetSpoolFolder(fSelectedPrinter->Folder());
} else {
fJobsBox->SetLabel(
B_TRANSLATE("Print jobs: No printer selected"));
fMakeDefault->SetEnabled(false);
fRemove->SetEnabled(false);
fSelectedPrinter = NULL;
fJobListView->SetSpoolFolder(NULL);
}
UpdateJobButtons();
UpdatePrinterButtons();
break;
}
case kMsgAddPrinter:
if (!fAddingPrinter) {
fAddingPrinter = true;
@@ -115,35 +90,39 @@ PrintersWindow::MessageReceived(BMessage* msg)
break;
case kMsgRemovePrinter:
{
fSelectedPrinter = fPrinterListView->SelectedItem();
if (fSelectedPrinter) fSelectedPrinter->Remove(fPrinterListView);
{
fSelectedPrinter = fPrinterListView->SelectedItem();
if (fSelectedPrinter)
fSelectedPrinter->Remove(fPrinterListView);
break;
}
case kMsgMakeDefaultPrinter:
{
PrinterItem* printer = fPrinterListView->SelectedItem();
if (printer && printer == fPrinterListView->ActivePrinter())
break;
BMessenger msgr;
if (printer && GetPrinterServerMessenger(msgr) == B_OK) {
BMessage setActivePrinter(B_SET_PROPERTY);
setActivePrinter.AddSpecifier("ActivePrinter");
setActivePrinter.AddString("data", printer->Name());
msgr.SendMessage(&setActivePrinter);
UpdatePrinterButtons();
}
break;
}
case kMsgMakeDefaultPrinter:
{
PrinterItem* printer = fPrinterListView->SelectedItem();
if (printer && printer == fPrinterListView->ActivePrinter())
break;
BMessenger msgr;
if (printer && GetPrinterServerMessenger(msgr) == B_OK) {
BMessage setActivePrinter(B_SET_PROPERTY);
setActivePrinter.AddSpecifier("ActivePrinter");
setActivePrinter.AddString("data", printer->Name());
msgr.SendMessage(&setActivePrinter);
UpdatePrinterButtons();
}
} break;
case kMsgCancelJob: fJobListView->CancelJob();
case kMsgCancelJob:
fJobListView->CancelJob();
break;
case kMsgRestartJob: fJobListView->RestartJob();
case kMsgRestartJob:
fJobListView->RestartJob();
break;
case kMsgJobSelected: UpdateJobButtons();
case kMsgJobSelected:
UpdateJobButtons();
break;
case B_PRINTER_CHANGED:
@@ -183,7 +162,8 @@ PrintersWindow::BuildGUI()
AddChild(backdrop);
// ------------------------ Next, build the printers overview box
BBox* printersBox = new BBox(BRect(boxInset, boxInset, r.Width()-boxInset, (r.Height()/2) - (boxInset/2)),
BBox* printersBox = new BBox(BRect(boxInset, boxInset,
r.Width() - boxInset, (r.Height()/2) - (boxInset/2)),
"printersBox", B_FOLLOW_ALL);
printersBox->SetFont(be_bold_font);
printersBox->SetLabel(B_TRANSLATE("Printers"));
@@ -202,7 +182,8 @@ PrintersWindow::BuildGUI()
// Remove button
fRemove = new BButton(BRect(5,30,5,30), "remove",
B_TRANSLATE("Remove"), new BMessage(kMsgRemovePrinter), B_FOLLOW_RIGHT);
B_TRANSLATE("Remove"), new BMessage(kMsgRemovePrinter),
B_FOLLOW_RIGHT);
printersBox->AddChild(fRemove);
fRemove->ResizeToPreferred();
@@ -211,7 +192,8 @@ PrintersWindow::BuildGUI()
// Make Default button
fMakeDefault = new BButton(BRect(5,60,5,60), "default",
B_TRANSLATE("Make default"), new BMessage(kMsgMakeDefaultPrinter), B_FOLLOW_RIGHT);
B_TRANSLATE("Make default"), new BMessage(kMsgMakeDefaultPrinter),
B_FOLLOW_RIGHT);
printersBox->AddChild(fMakeDefault);
fMakeDefault->ResizeToPreferred();
@@ -219,16 +201,16 @@ PrintersWindow::BuildGUI()
maxWidth = fMakeDefault->Bounds().Width();
// Resize all buttons to maximum width and align them to the right
float xPos = printersBox->Bounds().Width()-boxInset-maxWidth;
addButton->MoveTo(xPos, boxInset +8);
float xPos = printersBox->Bounds().Width() - boxInset - maxWidth;
addButton->MoveTo(xPos, boxInset + 8);
addButton->ResizeTo(maxWidth, addButton->Bounds().Height());
fRemove->MoveTo(xPos, boxInset + addButton->Bounds().Height() + boxInset +8);
fRemove->MoveTo(xPos,
boxInset + addButton->Bounds().Height() + boxInset + 8);
fRemove->ResizeTo(maxWidth, fRemove->Bounds().Height());
fMakeDefault->MoveTo(xPos, boxInset + addButton->Bounds().Height() +
boxInset + fRemove->Bounds().Height() +
boxInset +8);
boxInset + fRemove->Bounds().Height() + boxInset + 8);
fMakeDefault->ResizeTo(maxWidth, fMakeDefault->Bounds().Height());
// Disable all selection-based buttons
@@ -236,22 +218,24 @@ PrintersWindow::BuildGUI()
fMakeDefault->SetEnabled(false);
// Create listview with scroller
BRect listBounds(boxInset, boxInset+8, fMakeDefault->Frame().left - boxInset - B_V_SCROLL_BAR_WIDTH,
printersBox->Bounds().Height()-boxInset-3);
BRect listBounds(boxInset, boxInset + 8,
fMakeDefault->Frame().left - boxInset - B_V_SCROLL_BAR_WIDTH,
printersBox->Bounds().Height()- boxInset - 3);
fPrinterListView = new PrinterListView(listBounds);
BScrollView* pscroller = new BScrollView("printer_scroller", fPrinterListView,
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_FANCY_BORDER);
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_FANCY_BORDER);
printersBox->AddChild(pscroller);
// ------------------------ Lastly, build the jobs overview box
fJobsBox = new BBox(BRect(boxInset, (r.Height()/2)+(boxInset/2), Bounds().Width()-10, Bounds().Height() - boxInset),
"jobsBox", B_FOLLOW_LEFT_RIGHT+B_FOLLOW_BOTTOM);
fJobsBox = new BBox(BRect(boxInset, r.Height() / 2 + boxInset / 2,
Bounds().Width() - 10, Bounds().Height() - boxInset), "jobsBox",
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
fJobsBox->SetFont(be_bold_font);
fJobsBox->SetLabel(B_TRANSLATE("Print jobs: No printer selected"));
backdrop->AddChild(fJobsBox);
// Cancel Job Button
BButton* cancelButton = new BButton(BRect(5,5,5,5), "cancel",
BButton* cancelButton = new BButton(BRect(5, 5, 5, 5), "cancel",
B_TRANSLATE("Cancel job"), new BMessage(kMsgCancelJob),
B_FOLLOW_RIGHT+B_FOLLOW_TOP);
fJobsBox->AddChild(cancelButton);
@@ -261,9 +245,9 @@ PrintersWindow::BuildGUI()
maxWidth = cancelButton->Bounds().Width();
// Restart Job button
BButton* restartButton = new BButton(BRect(5,30,5,30), "restart",
BButton* restartButton = new BButton(BRect(5, 30, 5, 30), "restart",
B_TRANSLATE("Restart job"), new BMessage(kMsgRestartJob),
B_FOLLOW_RIGHT+B_FOLLOW_TOP);
B_FOLLOW_RIGHT | B_FOLLOW_TOP);
fJobsBox->AddChild(restartButton);
restartButton->ResizeToPreferred();
fRestart = restartButton;
@@ -272,11 +256,12 @@ PrintersWindow::BuildGUI()
maxWidth = restartButton->Bounds().Width();
// Resize all buttons to maximum width and align them to the right
xPos = fJobsBox->Bounds().Width()-boxInset-maxWidth;
cancelButton->MoveTo(xPos, boxInset +8);
xPos = fJobsBox->Bounds().Width() - boxInset - maxWidth;
cancelButton->MoveTo(xPos, boxInset + 8);
cancelButton->ResizeTo(maxWidth, cancelButton->Bounds().Height());
restartButton->MoveTo(xPos, boxInset + cancelButton->Bounds().Height() + boxInset +8);
restartButton->MoveTo(xPos, boxInset + cancelButton->Bounds().Height()
+ boxInset + 8);
restartButton->ResizeTo(maxWidth, restartButton->Bounds().Height());
// Disable all selection-based buttons
@@ -284,17 +269,17 @@ PrintersWindow::BuildGUI()
restartButton->SetEnabled(false);
// Create listview with scroller
listBounds = BRect(boxInset, boxInset+8, cancelButton->Frame().left - boxInset - B_V_SCROLL_BAR_WIDTH,
fJobsBox->Bounds().Height()-boxInset-3);
listBounds = BRect(boxInset, boxInset + 8,
cancelButton->Frame().left - boxInset - B_V_SCROLL_BAR_WIDTH,
fJobsBox->Bounds().Height() - boxInset - 3);
fJobListView = new JobListView(listBounds);
BScrollView* jscroller = new BScrollView("jobs_scroller", fJobListView,
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_FANCY_BORDER);
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_FANCY_BORDER);
fJobsBox->AddChild(jscroller);
// Determine min width
float width;
width = (jscroller->Bounds().Width() < pscroller->Bounds().Width()) ?
jscroller->Bounds().Width() : pscroller->Bounds().Width();
float width = (jscroller->Bounds().Width() < pscroller->Bounds().Width())
? jscroller->Bounds().Width() : pscroller->Bounds().Width();
// Resize boxes to the same size
jscroller->ResizeTo(width, jscroller->Bounds().Height());
@@ -303,33 +288,35 @@ PrintersWindow::BuildGUI()
bool
PrintersWindow::IsSelected(PrinterItem* printer) {
PrintersWindow::IsSelected(PrinterItem* printer)
{
return fSelectedPrinter && fSelectedPrinter == printer;
}
void
PrintersWindow::AddJob(SpoolFolder* folder, Job* job) {
if (IsSelected(folder->Item())) {
PrintersWindow::AddJob(SpoolFolder* folder, Job* job)
{
if (IsSelected(folder->Item()))
fJobListView->AddJob(job);
}
fPrinterListView->UpdateItem(folder->Item());
UpdatePrinterButtons();
}
void
PrintersWindow::RemoveJob(SpoolFolder* folder, Job* job) {
if (IsSelected(folder->Item())) {
PrintersWindow::RemoveJob(SpoolFolder* folder, Job* job)
{
if (IsSelected(folder->Item()))
fJobListView->RemoveJob(job);
}
fPrinterListView->UpdateItem(folder->Item());
UpdatePrinterButtons();
}
void
PrintersWindow::UpdateJob(SpoolFolder* folder, Job* job) {
PrintersWindow::UpdateJob(SpoolFolder* folder, Job* job)
{
if (IsSelected(folder->Item())) {
fJobListView->UpdateJob(job);
UpdateJobButtons();
@@ -340,7 +327,8 @@ PrintersWindow::UpdateJob(SpoolFolder* folder, Job* job) {
void
PrintersWindow::UpdatePrinterButtons() {
PrintersWindow::UpdatePrinterButtons()
{
PrinterItem* item = fPrinterListView->SelectedItem();
fRemove->SetEnabled(item && !item->HasPendingJobs());
fMakeDefault->SetEnabled(item && !item->IsActivePrinter());
@@ -348,7 +336,8 @@ PrintersWindow::UpdatePrinterButtons() {
void
PrintersWindow::UpdateJobButtons() {
PrintersWindow::UpdateJobButtons()
{
JobItem* item = fJobListView->SelectedItem();
if (item != NULL) {
Job* job = item->GetJob();
+12 -31
View File
@@ -1,37 +1,18 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2007 Haiku Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#ifndef PRINTERS_WINDOW_H
#define PRINTERS_WINDOW_H
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#ifndef _PRINTERS_WINDOW_H
#define _PRINTERS_WINDOW_H
#include <Box.h>
#include <Window.h>
class BBox;
class PrintersWindow;
class PrinterListView;
class JobListView;
@@ -74,4 +55,4 @@ private:
bool fAddingPrinter;
};
#endif // PRINTERS_WINDOW_H
#endif // _PRINTERS_WINDOW_H
+26 -46
View File
@@ -1,63 +1,43 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#include "SpoolFolder.h"
#include "JobListView.h"
#include "pr_server.h"
#include "Messages.h"
#include "Globals.h"
#include "Jobs.h"
#include "PrintersWindow.h"
//#include "pr_server.h"
#include <Messenger.h>
#include <Bitmap.h>
#include <String.h>
#include <Alert.h>
#include <Mime.h>
#include <Roster.h>
SpoolFolder::SpoolFolder(PrintersWindow* window, PrinterItem* item, const BDirectory& spoolDir)
: Folder(NULL, window, spoolDir)
, fWindow(window)
, fItem(item)
SpoolFolder::SpoolFolder(PrintersWindow* window, PrinterItem* item,
const BDirectory& spoolDir)
:
Folder(NULL, window, spoolDir),
fWindow(window),
fItem(item)
{
}
void SpoolFolder::Notify(Job* job, int kind)
void
SpoolFolder::Notify(Job* job, int kind)
{
switch (kind) {
case kJobAdded: fWindow->AddJob(this, job);
case kJobAdded:
fWindow->AddJob(this, job);
break;
case kJobRemoved: fWindow->RemoveJob(this, job);
case kJobRemoved:
fWindow->RemoveJob(this, job);
break;
case kJobAttrChanged: fWindow->UpdateJob(this, job);
case kJobAttrChanged:
fWindow->UpdateJob(this, job);
break;
default:
break;
default: ;
}
}
+22 -42
View File
@@ -1,54 +1,34 @@
/*****************************************************************************/
// Printers Preference Application.
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2001-2003 OpenBeOS Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// 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
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
/*
* Copyright 2001-2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
*/
#ifndef _SPOOL_FOLDER_H
#define _SPOOL_FOLDER_H
#ifndef SPOOL_FOLDER_H
#define SPOOL_FODLER_H
#include <Messenger.h>
#include <ListView.h>
#include <String.h>
#include "Jobs.h"
class PrintersWindow;
class PrinterItem;
class SpoolFolder : public Folder {
protected:
void Notify(Job* job, int kind);
PrintersWindow* fWindow;
PrinterItem* fItem;
class SpoolFolder : public Folder {
public:
SpoolFolder(PrintersWindow* window, PrinterItem* item, const BDirectory& spoolDir);
PrinterItem* Item() const { return fItem; }
SpoolFolder(PrintersWindow* window,
PrinterItem* item,
const BDirectory& spoolDir);
PrinterItem* Item() const { return fItem; }
protected:
void Notify(Job* job, int kind);
PrintersWindow* fWindow;
PrinterItem* fItem;
};
#endif
#endif // _SPOOL_FOLDER_H