libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / preferences / printers / TransportMenu.cpp
blobb27c249d03bfda4c996344bf2cf9b6ddafd93877
1 /*
2 * Copyright 2002-2010, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Michael Pfeiffer
7 * Philippe Houdoin
8 */
9 #include "TransportMenu.h"
12 #include <Catalog.h>
13 #include <MenuItem.h>
16 #undef B_TRANSLATION_CONTEXT
17 #define B_TRANSLATION_CONTEXT "TransportMenu"
20 TransportMenu::TransportMenu(const char* title, uint32 what,
21 const BMessenger& messenger, const BString& transportName)
23 BMenu(title),
24 fWhat(what),
25 fMessenger(messenger),
26 fTransportName(transportName)
31 bool
32 TransportMenu::AddDynamicItem(add_state state)
34 if (state != B_INITIAL_ADD)
35 return false;
37 BMenuItem* item = RemoveItem((int32)0);
38 while (item != NULL) {
39 delete item;
40 item = RemoveItem((int32)0);
43 BMessage msg;
44 msg.MakeEmpty();
45 msg.what = B_GET_PROPERTY;
46 msg.AddSpecifier("Ports");
47 BMessage reply;
48 if (fMessenger.SendMessage(&msg, &reply) != B_OK)
49 return false;
51 BString portId;
52 BString portName;
53 if (reply.FindString("port_id", &portId) != B_OK) {
54 // Show error message in submenu
55 BMessage* portMsg = new BMessage(fWhat);
56 AddItem(new BMenuItem(
57 B_TRANSLATE("No printer found!"), portMsg));
58 return false;
61 // Add ports to submenu
62 for (int32 i = 0; reply.FindString("port_id", i, &portId) == B_OK;
63 i++) {
64 if (reply.FindString("port_name", i, &portName) != B_OK
65 || !portName.Length())
66 portName = portId;
68 // Create menu item in submenu for port
69 BMessage* portMsg = new BMessage(fWhat);
70 portMsg->AddString("name", fTransportName);
71 portMsg->AddString("path", portId);
72 AddItem(new BMenuItem(portName.String(), portMsg));
75 return false;