* open 'Add printer dialog' when 'addp' message is sent to Printers preflet

* style changes


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21858 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2007-08-08 20:32:46 +00:00
parent 5851156445
commit 3f4090c83d
9 changed files with 72 additions and 68 deletions

View File

@ -49,6 +49,9 @@
#define PSRV_PRINT_SPOOLED_JOB 'psns'
#define PSRV_GET_DEFAULT_SETTINGS 'pdef'
// messages sent to Printers preflet
#define PRINTERS_ADD_PRINTER 'addp'
// mime file types
#define PSRV_PRINTER_FILETYPE "application/x-vnd.Be.printer"
#define PSRV_SPOOL_FILETYPE "application/x-vnd.Be.printer-spool"

View File

@ -12,6 +12,7 @@
#include "PrinterListView.h"
#include "pr_server.h"
#include "Globals.h"
#include "Messages.h"
#include <Box.h>
#include <Button.h>
@ -26,17 +27,10 @@
#include <StorageKit.h>
status_t
AddPrinterDialog::Start()
{
new AddPrinterDialog();
return B_OK;
}
AddPrinterDialog::AddPrinterDialog()
AddPrinterDialog::AddPrinterDialog(BWindow *parent)
: Inherited(BRect(78.0, 71.0, 400, 300), "Add Printer",
B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_ZOOMABLE)
, fPrintersPrefletMessenger(parent)
{
BuildGUI(0);
@ -44,6 +38,14 @@ AddPrinterDialog::AddPrinterDialog()
}
bool
AddPrinterDialog::QuitRequested()
{
fPrintersPrefletMessenger.SendMessage(kMsgAddPrinterClosed);
return Inherited::QuitRequested();
}
void
AddPrinterDialog::MessageReceived(BMessage* msg)
{

View File

@ -23,7 +23,9 @@ class AddPrinterDialog : public BWindow
typedef BWindow Inherited;
public:
static status_t Start();
AddPrinterDialog(BWindow *parent);
bool QuitRequested();
private:
enum MessageKind {
@ -32,7 +34,6 @@ class AddPrinterDialog : public BWindow
kNameChangedMsg,
};
AddPrinterDialog();
void MessageReceived(BMessage *msg);
void AddPrinter(BMessage *msg);
@ -44,6 +45,8 @@ class AddPrinterDialog : public BWindow
void AddPortSubMenu(BMenu *menu, const char *transport, const char *port);
void Update();
BMessenger fPrintersPrefletMessenger;
BTextControl *fName;
BPopUpMenu *fPrinter;
BPopUpMenu *fTransport;
@ -52,7 +55,7 @@ class AddPrinterDialog : public BWindow
BString fNameText;
BString fPrinterText;
BString fTransportText;
BString fTransportPathText;
BString fTransportPathText;
};
#endif

View File

@ -50,7 +50,7 @@ void JobListView::AttachedToWindow()
{
Inherited::AttachedToWindow();
SetSelectionMessage(new BMessage(MSG_JOB_SELECTED));
SetSelectionMessage(new BMessage(kMsgJobSelected));
SetTarget(Window());
}

View File

@ -1,42 +1,24 @@
/*****************************************************************************/
// 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-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Michael Pfeiffer
* Philippe Houdoin
*/
#ifndef MESSAGES_H
#define MESSAGES_H
#include <SupportDefs.h>
const uint32 MSG_ADD_PRINTER = 'AddP';
const uint32 MSG_REMOVE_PRINTER = 'RemP';
const uint32 MSG_MKDEF_PRINTER = 'MDfP';
const uint32 MSG_PRINTER_SELECTED = 'PSel';
const uint32 MSG_CANCEL_JOB = 'CncJ';
const uint32 MSG_RESTART_JOB = 'RstJ';
const uint32 MSG_JOB_SELECTED = 'JSel';
const uint32 kMsgAddPrinter = 'AddP';
const uint32 kMsgAddPrinterClosed = 'APCl';
const uint32 kMsgRemovePrinter = 'RemP';
const uint32 kMsgMakeDefaultPrinter = 'MDfP';
const uint32 kMsgPrinterSelected = 'PSel';
const uint32 kMsgCancelJob = 'CncJ';
const uint32 kMsgRestartJob = 'RstJ';
const uint32 kMsgJobSelected = 'JSel';
#endif

View File

@ -84,8 +84,8 @@ PrinterListView::AttachedToWindow()
{
Inherited::AttachedToWindow();
SetSelectionMessage(new BMessage(MSG_PRINTER_SELECTED));
SetInvocationMessage(new BMessage(MSG_MKDEF_PRINTER));
SetSelectionMessage(new BMessage(kMsgPrinterSelected));
SetInvocationMessage(new BMessage(kMsgMakeDefaultPrinter));
SetTarget(Window());
BPath path;

View File

@ -28,9 +28,9 @@
#include "Printers.h"
#ifndef PRINTERSWINDOW_H
#include "PrintersWindow.h"
#endif
#include "pr_server.h"
#include "Messages.h"
#include "PrintersWindow.h"
int main()
{
@ -51,12 +51,16 @@ void PrintersApp::ReadyToRun()
}
void PrintersApp::MessageReceived(BMessage* msg) {
if (msg->what == B_PRINTER_CHANGED) {
if (msg->what == B_PRINTER_CHANGED || msg->what == PRINTERS_ADD_PRINTER) {
// broadcast message
uint32 what = msg->what;
if (what == PRINTERS_ADD_PRINTER)
what = kMsgAddPrinter;
BWindow* w;
for (int32 i = 0; (w = WindowAt(i)) != NULL; i ++) {
BMessenger msgr(NULL, w);
msgr.SendMessage(B_PRINTER_CHANGED);
msgr.SendMessage(what);
}
} else {
BApplication::MessageReceived(msg);

View File

@ -47,6 +47,7 @@
PrintersWindow::PrintersWindow(BRect frame)
: Inherited(BRect(78.0, 71.0, 561.0, 409.0), "Printers", B_TITLED_WINDOW, B_NOT_H_RESIZABLE)
, fSelectedPrinter(NULL)
, fAddingPrinter(false)
{
BuildGUI();
}
@ -65,7 +66,7 @@ void PrintersWindow::MessageReceived(BMessage* msg)
{
switch(msg->what)
{
case MSG_PRINTER_SELECTED:
case kMsgPrinterSelected:
{
fSelectedPrinter = fPrinterListView->SelectedItem();
if (fSelectedPrinter)
@ -88,18 +89,25 @@ void PrintersWindow::MessageReceived(BMessage* msg)
}
break;
case MSG_ADD_PRINTER:
AddPrinterDialog::Start();
case kMsgAddPrinter:
if (!fAddingPrinter) {
fAddingPrinter = true;
new AddPrinterDialog(this);
}
break;
case kMsgAddPrinterClosed:
fAddingPrinter = false;
break;
case MSG_REMOVE_PRINTER:
case kMsgRemovePrinter:
{
fSelectedPrinter = fPrinterListView->SelectedItem();
if (fSelectedPrinter) fSelectedPrinter->Remove(fPrinterListView);
}
break;
case MSG_MKDEF_PRINTER:
case kMsgMakeDefaultPrinter:
{
int32 prIndex = fPrinterListView->CurrentSelection();
if (prIndex >= 0)
@ -121,13 +129,13 @@ void PrintersWindow::MessageReceived(BMessage* msg)
break;
case MSG_CANCEL_JOB: fJobListView->CancelJob();
case kMsgCancelJob: fJobListView->CancelJob();
break;
case MSG_RESTART_JOB: fJobListView->RestartJob();
case kMsgRestartJob: fJobListView->RestartJob();
break;
case MSG_JOB_SELECTED: UpdateJobButtons();
case kMsgJobSelected: UpdateJobButtons();
break;
case B_PRINTER_CHANGED:
@ -162,14 +170,14 @@ void PrintersWindow::BuildGUI()
float maxWidth = 0;
// Add Button
BButton* addButton = new BButton(BRect(5,5,5,5), "add", "Add " B_UTF8_ELLIPSIS, new BMessage(MSG_ADD_PRINTER), B_FOLLOW_RIGHT);
BButton* addButton = new BButton(BRect(5,5,5,5), "add", "Add " B_UTF8_ELLIPSIS, new BMessage(kMsgAddPrinter), B_FOLLOW_RIGHT);
printersBox->AddChild(addButton);
addButton->ResizeToPreferred();
maxWidth = addButton->Bounds().Width();
// Remove button
fRemove = new BButton(BRect(5,30,5,30), "remove", "Remove", new BMessage(MSG_REMOVE_PRINTER), B_FOLLOW_RIGHT);
fRemove = new BButton(BRect(5,30,5,30), "remove", "Remove", new BMessage(kMsgRemovePrinter), B_FOLLOW_RIGHT);
printersBox->AddChild(fRemove);
fRemove->ResizeToPreferred();
@ -177,7 +185,7 @@ void PrintersWindow::BuildGUI()
maxWidth = fRemove->Bounds().Width();
// Make Default button
fMakeDefault = new BButton(BRect(5,60,5,60), "default", "Make Default", new BMessage(MSG_MKDEF_PRINTER), B_FOLLOW_RIGHT);
fMakeDefault = new BButton(BRect(5,60,5,60), "default", "Make Default", new BMessage(kMsgMakeDefaultPrinter), B_FOLLOW_RIGHT);
printersBox->AddChild(fMakeDefault);
fMakeDefault->ResizeToPreferred();
@ -217,7 +225,7 @@ void PrintersWindow::BuildGUI()
backdrop->AddChild(fJobsBox);
// Cancel Job Button
BButton* cancelButton = new BButton(BRect(5,5,5,5), "cancel", "Cancel Job", new BMessage(MSG_CANCEL_JOB), B_FOLLOW_RIGHT+B_FOLLOW_TOP);
BButton* cancelButton = new BButton(BRect(5,5,5,5), "cancel", "Cancel Job", new BMessage(kMsgCancelJob), B_FOLLOW_RIGHT+B_FOLLOW_TOP);
fJobsBox->AddChild(cancelButton);
cancelButton->ResizeToPreferred();
fCancel = cancelButton;
@ -225,7 +233,7 @@ void PrintersWindow::BuildGUI()
maxWidth = cancelButton->Bounds().Width();
// Restart Job button
BButton* restartButton = new BButton(BRect(5,30,5,30), "restart", "Restart Job", new BMessage(MSG_RESTART_JOB), B_FOLLOW_RIGHT+B_FOLLOW_TOP);
BButton* restartButton = new BButton(BRect(5,30,5,30), "restart", "Restart Job", new BMessage(kMsgRestartJob), B_FOLLOW_RIGHT+B_FOLLOW_TOP);
fJobsBox->AddChild(restartButton);
restartButton->ResizeToPreferred();
fRestart = restartButton;

View File

@ -68,6 +68,8 @@ private:
BBox* fJobsBox;
PrinterItem* fSelectedPrinter;
bool fAddingPrinter;
};
#endif