Use new transport callbacks from printer preference.... transport addons now choose what to publish in the printers pref add printer dialog...
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23946 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -108,3 +108,22 @@ BDataIO* instantiate_transport(BDirectory* printer, BMessage* msg)
|
|||||||
delete transport;
|
delete transport;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t list_transport_ports(BMessage* msg)
|
||||||
|
{
|
||||||
|
BDirectory dir("/dev/parallel");
|
||||||
|
status_t rc;
|
||||||
|
|
||||||
|
if ((rc=dir.InitCheck()) != B_OK)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if ((rc=dir.Rewind()) != B_OK)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
while(dir.GetNextRef(&ref) == B_OK)
|
||||||
|
msg->AddString("port_id", ref.name);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,3 +109,22 @@ BDataIO* instantiate_transport(BDirectory* printer, BMessage* msg)
|
|||||||
delete transport;
|
delete transport;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t list_transport_ports(BMessage* msg)
|
||||||
|
{
|
||||||
|
BDirectory dir("/dev/ports");
|
||||||
|
status_t rc;
|
||||||
|
|
||||||
|
if ((rc=dir.InitCheck()) != B_OK)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if ((rc=dir.Rewind()) != B_OK)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
while(dir.GetNextRef(&ref) == B_OK)
|
||||||
|
msg->AddString("port_id", ref.name);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,24 @@ instantiate_transport(BDirectory *printer, BMessage *msg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t list_transport_ports(BMessage* msg)
|
||||||
|
{
|
||||||
|
BDirectory dir("/dev/printer/usb");
|
||||||
|
status_t rc;
|
||||||
|
|
||||||
|
if ((rc=dir.InitCheck()) != B_OK)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if ((rc=dir.Rewind()) != B_OK)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
while(dir.GetNextRef(&ref) == B_OK)
|
||||||
|
msg->AddString("port_id", ref.name);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implementation of USBTransport
|
// Implementation of USBTransport
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
AddPrinterDialog::AddPrinterDialog(BWindow *parent)
|
AddPrinterDialog::AddPrinterDialog(BWindow *parent)
|
||||||
: Inherited(BRect(78.0, 71.0, 400, 300), "Add Printer",
|
: Inherited(BRect(78.0, 71.0, 400, 300), "Add Printer",
|
||||||
@@ -218,7 +219,7 @@ AddPrinterDialog::BuildGUI(int stage)
|
|||||||
panel->AddChild(transportMenuField);
|
panel->AddChild(transportMenuField);
|
||||||
transportMenuField->GetPreferredSize(&w, &h);
|
transportMenuField->GetPreferredSize(&w, &h);
|
||||||
transportMenuField->ResizeTo(r.Width(), h);
|
transportMenuField->ResizeTo(r.Width(), h);
|
||||||
FillMenu(fTransport, "Print/transport", kTransportSelectedMsg);
|
FillTransportMenu(fTransport);
|
||||||
|
|
||||||
r.OffsetBy(0, transportMenuField->Bounds().Height() + kVMargin);
|
r.OffsetBy(0, transportMenuField->Bounds().Height() + kVMargin);
|
||||||
|
|
||||||
@@ -325,7 +326,6 @@ static directory_which gAddonDirs[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AddPrinterDialog::FillMenu(BMenu* menu, const char* path, uint32 what)
|
AddPrinterDialog::FillMenu(BMenu* menu, const char* path, uint32 what)
|
||||||
{
|
{
|
||||||
@@ -363,72 +363,77 @@ AddPrinterDialog::FillMenu(BMenu* menu, const char* path, uint32 what)
|
|||||||
if (entry.GetPath(&path) != B_OK)
|
if (entry.GetPath(&path) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool addMenuItem = true;
|
BMessage* msg = new BMessage(what);
|
||||||
// some hard coded special cases for transport add-ons
|
msg->AddString("name", path.Leaf());
|
||||||
if (menu == fTransport) {
|
menu->AddItem(new BMenuItem(path.Leaf(), msg));
|
||||||
const char* transport = path.Leaf();
|
|
||||||
// Network not implemented yet!
|
|
||||||
if (strcmp(transport, "Network") == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
addMenuItem = false;
|
|
||||||
|
|
||||||
if (strcmp(transport, "Serial Port") == 0) {
|
|
||||||
AddPortSubMenu(menu, transport, "/dev/ports");
|
|
||||||
} else if (strcmp(transport, "Parallel Port") == 0) {
|
|
||||||
AddPortSubMenu(menu, transport, "/dev/parallel");
|
|
||||||
} else if (strcmp(transport, "USB Port") == 0) {
|
|
||||||
AddPortSubMenu(menu, transport, "/dev/printer/usb");
|
|
||||||
} else {
|
|
||||||
addMenuItem = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addMenuItem) {
|
|
||||||
BMessage* msg = new BMessage(what);
|
|
||||||
msg->AddString("name", path.Leaf());
|
|
||||||
menu->AddItem(new BMenuItem(path.Leaf(), msg));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddPrinterDialog::FillTransportMenu(BMenu* menu)
|
||||||
void
|
|
||||||
AddPrinterDialog::AddPortSubMenu(BMenu* menu, const char* transport, const char* port)
|
|
||||||
{
|
{
|
||||||
BEntry entry(port);
|
BMessenger msgr;
|
||||||
BDirectory dir(&entry);
|
if (GetPrinterServerMessenger(msgr) != B_OK)
|
||||||
if (dir.InitCheck() != B_OK)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BMenu* subMenu = NULL;
|
for (long idx=0; ; idx++) {
|
||||||
BPath path;
|
BMessage reply, msg(B_GET_PROPERTY);
|
||||||
while (dir.GetNextEntry(&entry) == B_OK) {
|
msg.AddSpecifier("Transport", idx);
|
||||||
if (entry.GetPath(&path) != B_OK)
|
if (msgr.SendMessage(&msg,&reply) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
BMessenger transport;
|
||||||
|
if (reply.FindMessenger("result", &transport) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Got messenger to transport now
|
||||||
|
msg.MakeEmpty();
|
||||||
|
msg.what = B_GET_PROPERTY;
|
||||||
|
msg.AddSpecifier("Name");
|
||||||
|
if (transport.SendMessage(&msg,&reply) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// lazily create sub menu
|
BString transportName;
|
||||||
if (subMenu == NULL) {
|
if (reply.FindString("result",&transportName) != B_OK)
|
||||||
subMenu = new BMenu(transport);
|
continue;
|
||||||
menu->AddItem(subMenu);
|
|
||||||
subMenu->SetRadioMode(true);
|
// Now get ports...
|
||||||
int32 index = menu->IndexOf(subMenu);
|
BString portId, portName;
|
||||||
BMenuItem* item = menu->ItemAt(index);
|
status_t err;
|
||||||
if (item != NULL)
|
msg.MakeEmpty();
|
||||||
item->SetMessage(new BMessage(kTransportSelectedMsg));
|
msg.what = B_GET_PROPERTY;
|
||||||
|
msg.AddSpecifier("Ports");
|
||||||
|
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);
|
||||||
|
menuMsg->AddString("name", transportName);
|
||||||
|
menu->AddItem(new BMenuItem(transportName.String(), menuMsg));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup menu item for port
|
// We have at least one port; so create submenu
|
||||||
BMessage* msg = new BMessage(kTransportSelectedMsg);
|
BMenu* transportMenu = new BMenu(transportName.String());
|
||||||
msg->AddString("name", transport);
|
menu->AddItem(transportMenu);
|
||||||
msg->AddString("path", path.Leaf());
|
transportMenu->SetRadioMode(true);
|
||||||
BMenuItem* item = new BMenuItem(path.Leaf(), msg);
|
menu->ItemAt(menu->IndexOf(transportMenu))->
|
||||||
subMenu->AddItem(item);
|
SetMessage(new BMessage(kTransportSelectedMsg));
|
||||||
|
|
||||||
|
for (int32 pidx=0; reply.FindString("port_id", pidx, &portId) == B_OK; pidx++) {
|
||||||
|
reply.FindString("port_name", pidx, &portName);
|
||||||
|
|
||||||
|
if (!portName.Length())
|
||||||
|
portName = portId;
|
||||||
|
|
||||||
|
// Create menu item in submenu for port
|
||||||
|
BMessage* portMsg = new BMessage(kTransportSelectedMsg);
|
||||||
|
portMsg->AddString("name", transportName);
|
||||||
|
portMsg->AddString("path", portId);
|
||||||
|
transportMenu->AddItem(new BMenuItem(portName.String(), portMsg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AddPrinterDialog::Update()
|
AddPrinterDialog::Update()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class AddPrinterDialog : public BWindow
|
|||||||
void HandleChangedTransport(BMessage *msg);
|
void HandleChangedTransport(BMessage *msg);
|
||||||
|
|
||||||
void BuildGUI(int stage);
|
void BuildGUI(int stage);
|
||||||
|
void FillTransportMenu(BMenu *menu);
|
||||||
void FillMenu(BMenu *menu, const char *path, uint32 what);
|
void FillMenu(BMenu *menu, const char *path, uint32 what);
|
||||||
void AddPortSubMenu(BMenu *menu, const char *transport, const char *port);
|
void AddPortSubMenu(BMenu *menu, const char *transport, const char *port);
|
||||||
void Update();
|
void Update();
|
||||||
|
|||||||
Reference in New Issue
Block a user