* Dynamically create contents of transport sub menu.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39260 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "Globals.h"
|
||||
#include "Messages.h"
|
||||
#include "PrinterListView.h"
|
||||
#include "TransportMenu.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATE_CONTEXT
|
||||
@@ -379,34 +380,12 @@ AddPrinterDialog::_FillTransportMenu(BMenu* menu)
|
||||
}
|
||||
|
||||
// Create submenu
|
||||
BMenu* transportMenu = new BMenu(transportName.String());
|
||||
BMenu* transportMenu = new TransportMenu(transportName.String(),
|
||||
kTransportSelectedMsg, transport, transportName);
|
||||
menu->AddItem(transportMenu);
|
||||
transportMenu->SetRadioMode(true);
|
||||
menu->ItemAt(menu->IndexOf(transportMenu))->
|
||||
SetMessage(new BMessage(kTransportSelectedMsg));
|
||||
|
||||
|
||||
if (reply.FindString("port_id", &portId) != B_OK) {
|
||||
// Show error message in submenu
|
||||
BMessage* portMsg = new BMessage(kTransportSelectedMsg);
|
||||
transportMenu->AddItem(new BMenuItem(
|
||||
B_TRANSLATE("No printer found!"), portMsg));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add ports to submenu
|
||||
for (int32 i = 0; reply.FindString("port_id", i, &portId) == B_OK;
|
||||
i++) {
|
||||
if (reply.FindString("port_name", i, &portName) != B_OK
|
||||
|| !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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ Preference Printers :
|
||||
PrinterListView.cpp
|
||||
JobListView.cpp
|
||||
SpoolFolder.cpp
|
||||
TransportMenu.cpp
|
||||
Globals.cpp
|
||||
:
|
||||
be
|
||||
@@ -27,5 +28,6 @@ DoCatalogs Printers :
|
||||
JobListView.cpp
|
||||
PrinterListView.cpp
|
||||
PrintersWindow.cpp
|
||||
TransportMenu.cpp
|
||||
;
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2002-2010, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Pfeiffer
|
||||
* Philippe Houdoin
|
||||
*/
|
||||
#include "TransportMenu.h"
|
||||
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <MenuItem.h>
|
||||
|
||||
|
||||
#undef B_TRANSLATE_CONTEXT
|
||||
#define B_TRANSLATE_CONTEXT "TransportMenu"
|
||||
|
||||
|
||||
TransportMenu::TransportMenu(const char* title, uint32 what,
|
||||
const BMessenger& messenger, const BString& transportName)
|
||||
:
|
||||
BMenu(title),
|
||||
fWhat(what),
|
||||
fMessenger(messenger),
|
||||
fTransportName(transportName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TransportMenu::AddDynamicItem(add_state state)
|
||||
{
|
||||
if (state != B_INITIAL_ADD)
|
||||
return false;
|
||||
|
||||
BMenuItem* item = RemoveItem((int32)0);
|
||||
while (item != NULL) {
|
||||
delete item;
|
||||
item = RemoveItem((int32)0);
|
||||
}
|
||||
|
||||
BMessage msg;
|
||||
msg.MakeEmpty();
|
||||
msg.what = B_GET_PROPERTY;
|
||||
msg.AddSpecifier("Ports");
|
||||
BMessage reply;
|
||||
if (fMessenger.SendMessage(&msg, &reply) != B_OK)
|
||||
return false;
|
||||
|
||||
BString portId;
|
||||
BString portName;
|
||||
if (reply.FindString("port_id", &portId) != B_OK) {
|
||||
// Show error message in submenu
|
||||
BMessage* portMsg = new BMessage(fWhat);
|
||||
AddItem(new BMenuItem(
|
||||
B_TRANSLATE("No printer found!"), portMsg));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add ports to submenu
|
||||
for (int32 i = 0; reply.FindString("port_id", i, &portId) == B_OK;
|
||||
i++) {
|
||||
if (reply.FindString("port_name", i, &portName) != B_OK
|
||||
|| !portName.Length())
|
||||
portName = portId;
|
||||
|
||||
// Create menu item in submenu for port
|
||||
BMessage* portMsg = new BMessage(fWhat);
|
||||
portMsg->AddString("name", fTransportName);
|
||||
portMsg->AddString("path", portId);
|
||||
AddItem(new BMenuItem(portName.String(), portMsg));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Pfeiffer
|
||||
*/
|
||||
|
||||
#ifndef _TRANSPORT_MENU_H
|
||||
#define _TRANSPORT_MENU_H
|
||||
|
||||
|
||||
#include <Menu.h>
|
||||
#include <Messenger.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class TransportMenu : public BMenu
|
||||
{
|
||||
public:
|
||||
TransportMenu(const char* title, uint32 what,
|
||||
const BMessenger& messenger, const BString& transportName);
|
||||
|
||||
bool AddDynamicItem(add_state s);
|
||||
|
||||
private:
|
||||
uint32 fWhat;
|
||||
BMessenger fMessenger;
|
||||
BString fTransportName;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user