PrefDCC.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. * Todd Lair
  21. */
  22. #include "NumericFilter.h"
  23. #include "PrefDCC.h"
  24. #include "Vision.h"
  25. #include "VTextControl.h"
  26. #include <Box.h>
  27. #include <CheckBox.h>
  28. #include <Menu.h>
  29. #include <MenuField.h>
  30. #include <MenuItem.h>
  31. #include <Path.h>
  32. #include <ctype.h>
  33. #include <stdlib.h>
  34. DCCPrefsView::DCCPrefsView (BRect frame)
  35. : BView (frame, "DCC prefs", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS)
  36. {
  37. SetViewColor (ui_color (B_PANEL_BACKGROUND_COLOR));
  38. BMenu *menu (new BMenu (S_PREFDCC_BLOCK_SIZE));
  39. menu->AddItem (new BMenuItem ("1024", new BMessage (M_BLOCK_SIZE_CHANGED)));
  40. menu->AddItem (new BMenuItem ("2048", new BMessage (M_BLOCK_SIZE_CHANGED)));
  41. menu->AddItem (new BMenuItem ("4096", new BMessage (M_BLOCK_SIZE_CHANGED)));
  42. menu->AddItem (new BMenuItem ("8192", new BMessage (M_BLOCK_SIZE_CHANGED)));
  43. fBlockSize = new BMenuField (BRect (0,0,0,0), NULL, S_PREFDCC_BLOCK_SIZE, menu);
  44. fAutoAccept = new BCheckBox (BRect (0,0,0,0), NULL, S_PREFDCC_AUTOACK,
  45. new BMessage (M_AUTO_ACCEPT_CHANGED));
  46. fPrivateCheck = new BCheckBox (BRect (0,0,0,0), NULL, S_PREFDCC_PRIVATE,
  47. new BMessage (M_DCC_PRIVATE_CHANGED));
  48. fDefDir = new VTextControl (BRect (0,0,0,0), NULL, S_PREFDCC_DEFPATH, "", new BMessage (M_DEFAULT_PATH_CHANGED));
  49. fDefDir->SetDivider (fDefDir->StringWidth (S_PREFDCC_DEFPATH + 5));
  50. fBox = new BBox (BRect (0,0,0,0), NULL);
  51. fBox->SetLabel (S_PREFDCC_PORTRANGE);
  52. AddChild (fDefDir);
  53. AddChild (fPrivateCheck);
  54. AddChild (fAutoAccept);
  55. AddChild (fBlockSize);
  56. AddChild (fBox);
  57. fDccPortMin = new VTextControl (BRect (0,0,0,0), NULL, S_PREFDCC_PORTMIN, "",
  58. new BMessage (M_DCC_MIN_PORT_CHANGED));
  59. fDccPortMin->TextView()->AddFilter (new NumericFilter());
  60. fDccPortMin->SetDivider (fDccPortMin->StringWidth (S_PREFDCC_PORTMIN) + 5);
  61. fBox->AddChild (fDccPortMin);
  62. fDccPortMax = new VTextControl (BRect (0,0,0,0), NULL, S_PREFDCC_PORTMAX, "",
  63. new BMessage (M_DCC_MAX_PORT_CHANGED));
  64. fDccPortMax->SetDivider (fDccPortMax->StringWidth (S_PREFDCC_PORTMAX) + 5);
  65. fDccPortMax->TextView()->AddFilter (new NumericFilter());
  66. fBox->AddChild (fDccPortMax);
  67. }
  68. DCCPrefsView::~DCCPrefsView (void)
  69. {
  70. }
  71. void
  72. DCCPrefsView::AttachedToWindow (void)
  73. {
  74. BView::AttachedToWindow ();
  75. fBlockSize->Menu()->SetTargetForItems (this);
  76. fAutoAccept->SetTarget (this);
  77. fDefDir->SetTarget (this);
  78. fDefDir->ResizeToPreferred ();
  79. fDefDir->ResizeTo (Bounds().Width() - 15, fDefDir->Bounds().Height());
  80. fDefDir->MoveTo (10, 10);
  81. fAutoAccept->ResizeToPreferred ();
  82. fAutoAccept->MoveTo (fDefDir->Frame().left, fDefDir->Frame().bottom + 5);
  83. fPrivateCheck->SetTarget (this);
  84. fPrivateCheck->ResizeToPreferred ();
  85. fPrivateCheck->MoveTo (fAutoAccept->Frame().left, fAutoAccept->Frame().bottom + 5);
  86. fBlockSize->ResizeToPreferred ();
  87. fBlockSize->ResizeTo (Bounds().Width() - 15, fBlockSize->Bounds().Height());
  88. fBlockSize->SetDivider (fBlockSize->StringWidth (S_PREFDCC_BLOCK_SIZE) + 5);
  89. fBlockSize->MoveTo (fPrivateCheck->Frame().left, fPrivateCheck->Frame().bottom + 5);
  90. fBlockSize->Menu()->SetLabelFromMarked (true);
  91. const char *defPath (vision_app->GetString ("dccDefPath"));
  92. fDefDir->SetText (defPath);
  93. if (vision_app->GetBool ("dccAutoAccept"))
  94. fAutoAccept->SetValue (B_CONTROL_ON);
  95. else
  96. fDefDir->SetEnabled (false);
  97. if (vision_app->GetBool ("dccPrivateCheck"))
  98. fPrivateCheck->SetValue (B_CONTROL_ON);
  99. fDccPortMin->ResizeToPreferred();
  100. fDccPortMax->ResizeToPreferred();
  101. fDccPortMin->SetTarget (this);
  102. fDccPortMax->SetTarget (this);
  103. fBox->ResizeTo (Bounds().Width() - 20, fDccPortMin->Bounds().Height()+30);
  104. fBox->MoveTo (fBlockSize->Frame().left, fBlockSize->Frame().bottom + 25);
  105. fDccPortMin->ResizeTo ((fBox->Bounds().Width() / 2.0) - 15, fDccPortMin->Bounds().Height());
  106. fDccPortMax->ResizeTo (fDccPortMin->Bounds().Width(), fDccPortMin->Bounds().Height());
  107. fDccPortMin->MoveTo (5,20);
  108. fDccPortMax->MoveTo (fDccPortMin->Frame().right + 5, fDccPortMin->Frame().top);
  109. fDccPortMin->SetText (vision_app->GetString ("dccMinPort"));
  110. fDccPortMax->SetText (vision_app->GetString ("dccMaxPort"));
  111. const char *dccBlock (vision_app->GetString ("dccBlockSize"));
  112. BMenuItem *item (fBlockSize->Menu()->FindItem (dccBlock));
  113. if (item)
  114. dynamic_cast<BInvoker *>(item)->Invoke();
  115. }
  116. void
  117. DCCPrefsView::AllAttached (void)
  118. {
  119. BView::AllAttached ();
  120. }
  121. void
  122. DCCPrefsView::FrameResized (float width, float height)
  123. {
  124. BView::FrameResized (width, height);
  125. }
  126. void
  127. DCCPrefsView::MessageReceived (BMessage *msg)
  128. {
  129. switch (msg->what)
  130. {
  131. case M_BLOCK_SIZE_CHANGED:
  132. {
  133. BMenuItem *it (NULL);
  134. msg->FindPointer ("source", reinterpret_cast<void **>(&it));
  135. if (it)
  136. vision_app->SetString ("dccBlockSize", 0, it->Label());
  137. }
  138. break;
  139. case M_DEFAULT_PATH_CHANGED:
  140. {
  141. const char *path (fDefDir->Text());
  142. BPath testPath (path, NULL, true);
  143. if (testPath.InitCheck() == B_OK)
  144. vision_app->SetString ("dccDefPath", 0, path);
  145. }
  146. break;
  147. case M_AUTO_ACCEPT_CHANGED:
  148. {
  149. int32 val (fAutoAccept->Value());
  150. fDefDir->SetEnabled (val == B_CONTROL_ON);
  151. vision_app->SetBool ("dccAutoAccept", val);
  152. }
  153. break;
  154. case M_DCC_MIN_PORT_CHANGED:
  155. {
  156. const char *portMin (fDccPortMin->Text());
  157. if (portMin != NULL)
  158. vision_app->SetString ("dccMinPort", 0, portMin);
  159. }
  160. break;
  161. case M_DCC_MAX_PORT_CHANGED:
  162. {
  163. const char *portMax (fDccPortMax->Text());
  164. if (portMax != NULL)
  165. vision_app->SetString ("dccMaxPort", 0, portMax);
  166. }
  167. break;
  168. case M_DCC_PRIVATE_CHANGED:
  169. {
  170. vision_app->SetBool("dccPrivateCheck", fPrivateCheck->Value() == B_CONTROL_ON);
  171. }
  172. break;
  173. default:
  174. BView::MessageReceived (msg);
  175. break;
  176. }
  177. }