2 * Copyright 2002-2010, Haiku.
3 * Distributed under the terms of the MIT License.
9 #include "TransportMenu.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
)
25 fMessenger(messenger
),
26 fTransportName(transportName
)
32 TransportMenu::AddDynamicItem(add_state state
)
34 if (state
!= B_INITIAL_ADD
)
37 BMenuItem
* item
= RemoveItem((int32
)0);
38 while (item
!= NULL
) {
40 item
= RemoveItem((int32
)0);
45 msg
.what
= B_GET_PROPERTY
;
46 msg
.AddSpecifier("Ports");
48 if (fMessenger
.SendMessage(&msg
, &reply
) != B_OK
)
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
));
61 // Add ports to submenu
62 for (int32 i
= 0; reply
.FindString("port_id", i
, &portId
) == B_OK
;
64 if (reply
.FindString("port_name", i
, &portName
) != B_OK
65 || !portName
.Length())
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
));