NetworkMenu.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is Vision.
  13. *
  14. * The Initial Developer of the Original Code is The Vision Team.
  15. * Portions created by The Vision Team are
  16. * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
  17. * Reserved.
  18. *
  19. * Contributor(s): Rene Gollent
  20. */
  21. #include <MenuItem.h>
  22. #include <Messenger.h>
  23. #include "NetworkMenu.h"
  24. #include "Vision.h"
  25. NetworkMenu::NetworkMenu (const char *title, uint32 what, BMessenger msgTarget)
  26. : BMenu (title),
  27. fMsgConst (what),
  28. fTarget (msgTarget)
  29. {
  30. }
  31. NetworkMenu::~NetworkMenu (void)
  32. {
  33. }
  34. void
  35. NetworkMenu::AttachedToWindow (void)
  36. {
  37. if (CountItems())
  38. {
  39. BMenuItem *item (NULL);
  40. while ((item = RemoveItem((int32)0)) != NULL)
  41. delete item;
  42. }
  43. BMessage msg;
  44. BMessage *invoke (NULL);
  45. for (int32 i = 0; (msg = vision_app->GetNetwork (i)), !msg.HasBool ("error"); i++)
  46. {
  47. const char *name = msg.FindString ("name");
  48. invoke = new BMessage (fMsgConst);
  49. invoke->AddString ("network", name);
  50. BMenuItem *item (new BMenuItem(name, invoke));
  51. AddItem (item);
  52. if (!vision_app->CheckNetworkValid (name))
  53. item->SetEnabled (false);
  54. }
  55. SetTargetForItems (fTarget.Target(NULL));
  56. BMenu::AttachedToWindow();
  57. }