* 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
+3
View File
@@ -49,6 +49,9 @@
#define PSRV_PRINT_SPOOLED_JOB 'psns' #define PSRV_PRINT_SPOOLED_JOB 'psns'
#define PSRV_GET_DEFAULT_SETTINGS 'pdef' #define PSRV_GET_DEFAULT_SETTINGS 'pdef'
// messages sent to Printers preflet
#define PRINTERS_ADD_PRINTER 'addp'
// mime file types // mime file types
#define PSRV_PRINTER_FILETYPE "application/x-vnd.Be.printer" #define PSRV_PRINTER_FILETYPE "application/x-vnd.Be.printer"
#define PSRV_SPOOL_FILETYPE "application/x-vnd.Be.printer-spool" #define PSRV_SPOOL_FILETYPE "application/x-vnd.Be.printer-spool"
+11 -9
View File
@@ -12,6 +12,7 @@
#include "PrinterListView.h" #include "PrinterListView.h"
#include "pr_server.h" #include "pr_server.h"
#include "Globals.h" #include "Globals.h"
#include "Messages.h"
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
@@ -26,17 +27,10 @@
#include <StorageKit.h> #include <StorageKit.h>
status_t AddPrinterDialog::AddPrinterDialog(BWindow *parent)
AddPrinterDialog::Start()
{
new AddPrinterDialog();
return B_OK;
}
AddPrinterDialog::AddPrinterDialog()
: Inherited(BRect(78.0, 71.0, 400, 300), "Add Printer", : Inherited(BRect(78.0, 71.0, 400, 300), "Add Printer",
B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_ZOOMABLE) B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_ZOOMABLE)
, fPrintersPrefletMessenger(parent)
{ {
BuildGUI(0); BuildGUI(0);
@@ -44,6 +38,14 @@ AddPrinterDialog::AddPrinterDialog()
} }
bool
AddPrinterDialog::QuitRequested()
{
fPrintersPrefletMessenger.SendMessage(kMsgAddPrinterClosed);
return Inherited::QuitRequested();
}
void void
AddPrinterDialog::MessageReceived(BMessage* msg) AddPrinterDialog::MessageReceived(BMessage* msg)
{ {
+6 -3
View File
@@ -23,7 +23,9 @@ class AddPrinterDialog : public BWindow
typedef BWindow Inherited; typedef BWindow Inherited;
public: public:
static status_t Start(); AddPrinterDialog(BWindow *parent);
bool QuitRequested();
private: private:
enum MessageKind { enum MessageKind {
@@ -32,7 +34,6 @@ class AddPrinterDialog : public BWindow
kNameChangedMsg, kNameChangedMsg,
}; };
AddPrinterDialog();
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void AddPrinter(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 AddPortSubMenu(BMenu *menu, const char *transport, const char *port);
void Update(); void Update();
BMessenger fPrintersPrefletMessenger;
BTextControl *fName; BTextControl *fName;
BPopUpMenu *fPrinter; BPopUpMenu *fPrinter;
BPopUpMenu *fTransport; BPopUpMenu *fTransport;
@@ -52,7 +55,7 @@ class AddPrinterDialog : public BWindow
BString fNameText; BString fNameText;
BString fPrinterText; BString fPrinterText;
BString fTransportText; BString fTransportText;
BString fTransportPathText; BString fTransportPathText;
}; };
#endif #endif
+1 -1
View File
@@ -50,7 +50,7 @@ void JobListView::AttachedToWindow()
{ {
Inherited::AttachedToWindow(); Inherited::AttachedToWindow();
SetSelectionMessage(new BMessage(MSG_JOB_SELECTED)); SetSelectionMessage(new BMessage(kMsgJobSelected));
SetTarget(Window()); SetTarget(Window());
} }
+17 -35
View File
@@ -1,42 +1,24 @@
/*****************************************************************************/ /*
// Printers Preference Application. * Copyright 2001-2007, Haiku.
// * Distributed under the terms of the MIT License.
// This application and all source files used in its construction, except *
// where noted, are licensed under the MIT License, and have been written * Authors:
// and are: * Michael Pfeiffer
// * Philippe Houdoin
// 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 MESSAGES_H #ifndef MESSAGES_H
#define MESSAGES_H #define MESSAGES_H
#include <SupportDefs.h> #include <SupportDefs.h>
const uint32 MSG_ADD_PRINTER = 'AddP'; const uint32 kMsgAddPrinter = 'AddP';
const uint32 MSG_REMOVE_PRINTER = 'RemP'; const uint32 kMsgAddPrinterClosed = 'APCl';
const uint32 MSG_MKDEF_PRINTER = 'MDfP'; const uint32 kMsgRemovePrinter = 'RemP';
const uint32 MSG_PRINTER_SELECTED = 'PSel'; const uint32 kMsgMakeDefaultPrinter = 'MDfP';
const uint32 MSG_CANCEL_JOB = 'CncJ'; const uint32 kMsgPrinterSelected = 'PSel';
const uint32 MSG_RESTART_JOB = 'RstJ'; const uint32 kMsgCancelJob = 'CncJ';
const uint32 MSG_JOB_SELECTED = 'JSel'; const uint32 kMsgRestartJob = 'RstJ';
const uint32 kMsgJobSelected = 'JSel';
#endif #endif
+2 -2
View File
@@ -84,8 +84,8 @@ PrinterListView::AttachedToWindow()
{ {
Inherited::AttachedToWindow(); Inherited::AttachedToWindow();
SetSelectionMessage(new BMessage(MSG_PRINTER_SELECTED)); SetSelectionMessage(new BMessage(kMsgPrinterSelected));
SetInvocationMessage(new BMessage(MSG_MKDEF_PRINTER)); SetInvocationMessage(new BMessage(kMsgMakeDefaultPrinter));
SetTarget(Window()); SetTarget(Window());
BPath path; BPath path;
+9 -5
View File
@@ -28,9 +28,9 @@
#include "Printers.h" #include "Printers.h"
#ifndef PRINTERSWINDOW_H #include "pr_server.h"
#include "PrintersWindow.h" #include "Messages.h"
#endif #include "PrintersWindow.h"
int main() int main()
{ {
@@ -51,12 +51,16 @@ void PrintersApp::ReadyToRun()
} }
void PrintersApp::MessageReceived(BMessage* msg) { void PrintersApp::MessageReceived(BMessage* msg) {
if (msg->what == B_PRINTER_CHANGED) { if (msg->what == B_PRINTER_CHANGED || msg->what == PRINTERS_ADD_PRINTER) {
// broadcast message // broadcast message
uint32 what = msg->what;
if (what == PRINTERS_ADD_PRINTER)
what = kMsgAddPrinter;
BWindow* w; BWindow* w;
for (int32 i = 0; (w = WindowAt(i)) != NULL; i ++) { for (int32 i = 0; (w = WindowAt(i)) != NULL; i ++) {
BMessenger msgr(NULL, w); BMessenger msgr(NULL, w);
msgr.SendMessage(B_PRINTER_CHANGED); msgr.SendMessage(what);
} }
} else { } else {
BApplication::MessageReceived(msg); BApplication::MessageReceived(msg);
+21 -13
View File
@@ -47,6 +47,7 @@
PrintersWindow::PrintersWindow(BRect frame) PrintersWindow::PrintersWindow(BRect frame)
: Inherited(BRect(78.0, 71.0, 561.0, 409.0), "Printers", B_TITLED_WINDOW, B_NOT_H_RESIZABLE) : Inherited(BRect(78.0, 71.0, 561.0, 409.0), "Printers", B_TITLED_WINDOW, B_NOT_H_RESIZABLE)
, fSelectedPrinter(NULL) , fSelectedPrinter(NULL)
, fAddingPrinter(false)
{ {
BuildGUI(); BuildGUI();
} }
@@ -65,7 +66,7 @@ void PrintersWindow::MessageReceived(BMessage* msg)
{ {
switch(msg->what) switch(msg->what)
{ {
case MSG_PRINTER_SELECTED: case kMsgPrinterSelected:
{ {
fSelectedPrinter = fPrinterListView->SelectedItem(); fSelectedPrinter = fPrinterListView->SelectedItem();
if (fSelectedPrinter) if (fSelectedPrinter)
@@ -88,18 +89,25 @@ void PrintersWindow::MessageReceived(BMessage* msg)
} }
break; break;
case MSG_ADD_PRINTER: case kMsgAddPrinter:
AddPrinterDialog::Start(); if (!fAddingPrinter) {
fAddingPrinter = true;
new AddPrinterDialog(this);
}
break;
case kMsgAddPrinterClosed:
fAddingPrinter = false;
break; break;
case MSG_REMOVE_PRINTER: case kMsgRemovePrinter:
{ {
fSelectedPrinter = fPrinterListView->SelectedItem(); fSelectedPrinter = fPrinterListView->SelectedItem();
if (fSelectedPrinter) fSelectedPrinter->Remove(fPrinterListView); if (fSelectedPrinter) fSelectedPrinter->Remove(fPrinterListView);
} }
break; break;
case MSG_MKDEF_PRINTER: case kMsgMakeDefaultPrinter:
{ {
int32 prIndex = fPrinterListView->CurrentSelection(); int32 prIndex = fPrinterListView->CurrentSelection();
if (prIndex >= 0) if (prIndex >= 0)
@@ -121,13 +129,13 @@ void PrintersWindow::MessageReceived(BMessage* msg)
break; break;
case MSG_CANCEL_JOB: fJobListView->CancelJob(); case kMsgCancelJob: fJobListView->CancelJob();
break; break;
case MSG_RESTART_JOB: fJobListView->RestartJob(); case kMsgRestartJob: fJobListView->RestartJob();
break; break;
case MSG_JOB_SELECTED: UpdateJobButtons(); case kMsgJobSelected: UpdateJobButtons();
break; break;
case B_PRINTER_CHANGED: case B_PRINTER_CHANGED:
@@ -162,14 +170,14 @@ void PrintersWindow::BuildGUI()
float maxWidth = 0; float maxWidth = 0;
// Add Button // 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); printersBox->AddChild(addButton);
addButton->ResizeToPreferred(); addButton->ResizeToPreferred();
maxWidth = addButton->Bounds().Width(); maxWidth = addButton->Bounds().Width();
// Remove button // 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); printersBox->AddChild(fRemove);
fRemove->ResizeToPreferred(); fRemove->ResizeToPreferred();
@@ -177,7 +185,7 @@ void PrintersWindow::BuildGUI()
maxWidth = fRemove->Bounds().Width(); maxWidth = fRemove->Bounds().Width();
// Make Default button // 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); printersBox->AddChild(fMakeDefault);
fMakeDefault->ResizeToPreferred(); fMakeDefault->ResizeToPreferred();
@@ -217,7 +225,7 @@ void PrintersWindow::BuildGUI()
backdrop->AddChild(fJobsBox); backdrop->AddChild(fJobsBox);
// Cancel Job Button // 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); fJobsBox->AddChild(cancelButton);
cancelButton->ResizeToPreferred(); cancelButton->ResizeToPreferred();
fCancel = cancelButton; fCancel = cancelButton;
@@ -225,7 +233,7 @@ void PrintersWindow::BuildGUI()
maxWidth = cancelButton->Bounds().Width(); maxWidth = cancelButton->Bounds().Width();
// Restart Job button // 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); fJobsBox->AddChild(restartButton);
restartButton->ResizeToPreferred(); restartButton->ResizeToPreferred();
fRestart = restartButton; fRestart = restartButton;
+2
View File
@@ -68,6 +68,8 @@ private:
BBox* fJobsBox; BBox* fJobsBox;
PrinterItem* fSelectedPrinter; PrinterItem* fSelectedPrinter;
bool fAddingPrinter;
}; };
#endif #endif