ConfigSubscriptions.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. ==============================================================================
  3. This is an automatically generated GUI class created by the Introjucer!
  4. Be careful when adding custom code to these files, as only the code within
  5. the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  6. and re-saved.
  7. Created with Introjucer version: 3.1.0
  8. ------------------------------------------------------------------------------
  9. The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
  10. Copyright 2004-13 by Raw Material Software Ltd.
  11. ==============================================================================
  12. */
  13. //[Headers] You can add your own extra header files here...
  14. #include "Constants.h"
  15. #include "LinJam.h"
  16. #include "Subscriptions.h"
  17. //[/Headers]
  18. #include "ConfigSubscriptions.h"
  19. //[MiscUserDefs] You can add your own user definitions and misc code here...
  20. //[/MiscUserDefs]
  21. //==============================================================================
  22. ConfigSubscriptions::ConfigSubscriptions (ValueTree config_store)
  23. : configStore(config_store)
  24. {
  25. addAndMakeVisible (subscribeButton = new ToggleButton ("subscribeButton"));
  26. subscribeButton->setExplicitFocusOrder (1);
  27. subscribeButton->setButtonText (TRANS("auto-receive"));
  28. subscribeButton->addListener (this);
  29. subscribeButton->setToggleState (true, dontSendNotification);
  30. subscribeButton->setColour (ToggleButton::textColourId, Colours::white);
  31. addAndMakeVisible (ignoreButton = new ToggleButton ("ignoreButton"));
  32. ignoreButton->setExplicitFocusOrder (2);
  33. ignoreButton->setButtonText (TRANS("auto-ignore"));
  34. ignoreButton->addListener (this);
  35. ignoreButton->setToggleState (true, dontSendNotification);
  36. ignoreButton->setColour (ToggleButton::textColourId, Colours::white);
  37. addAndMakeVisible (bansLabel = new Label ("bansLabel",
  38. TRANS("ignored users")));
  39. bansLabel->setFont (Font (15.00f, Font::plain));
  40. bansLabel->setJustificationType (Justification::centredTop);
  41. bansLabel->setEditable (false, false, false);
  42. bansLabel->setColour (Label::textColourId, Colours::white);
  43. bansLabel->setColour (TextEditor::textColourId, Colours::black);
  44. bansLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
  45. addAndMakeVisible (subscriptionsViewport = new Viewport ("subscriptionsViewport"));
  46. subscriptionsViewport->setExplicitFocusOrder (3);
  47. subscriptionsViewport->setScrollBarsShown (true, false);
  48. subscriptionsViewport->setScrollBarThickness (12);
  49. subscriptionsViewport->setViewedComponent (new Subscriptions (config_store));
  50. //[UserPreSize]
  51. //[/UserPreSize]
  52. setSize (614, 434);
  53. //[Constructor] You can add your own custom stuff here..
  54. int auto_subscribe_mode = int(this->configStore[CONFIG::SUBSCRIBE_MODE_KEY]) ;
  55. bool should_sub = auto_subscribe_mode != (int)NJClient::SUBSCRIBE_ALLOW ;
  56. bool should_ban = auto_subscribe_mode == (int)NJClient::SUBSCRIBE_DENY ;
  57. this->subscribeButton ->setToggleState(should_sub , dontSendNotification) ;
  58. this->ignoreButton ->setToggleState(should_ban , dontSendNotification) ;
  59. this->subscriptionsViewport->setScrollBarThickness(GUI::CONFIG_SCROLLBAR_W) ;
  60. this->subscriptionsViewport->setBounds(GUI::SUBSCRIPTIONS_X , GUI::SUBSCRIPTIONS_Y ,
  61. GUI::SUBSCRIPTIONS_W , GUI::SUBSCRIPTIONS_H ) ;
  62. //[/Constructor]
  63. }
  64. ConfigSubscriptions::~ConfigSubscriptions()
  65. {
  66. //[Destructor_pre]. You can add your own custom destruction code here..
  67. //[/Destructor_pre]
  68. subscribeButton = nullptr;
  69. ignoreButton = nullptr;
  70. bansLabel = nullptr;
  71. subscriptionsViewport = nullptr;
  72. //[Destructor]. You can add your own custom destruction code here..
  73. //[/Destructor]
  74. }
  75. //==============================================================================
  76. void ConfigSubscriptions::paint (Graphics& g)
  77. {
  78. //[UserPrePaint] Add your own custom painting code here..
  79. //[/UserPrePaint]
  80. g.setColour (Colour (0xff200000));
  81. g.fillRoundedRectangle (0.0f, 0.0f, 192.0f, 172.0f, 10.000f);
  82. g.setColour (Colour (0xff101010));
  83. g.fillRoundedRectangle (20.0f, 64.0f, 152.0f, 84.0f, 10.000f);
  84. g.setColour (Colours::white);
  85. g.drawRoundedRectangle (20.0f, 64.0f, 152.0f, 84.0f, 10.000f, 1.000f);
  86. //[UserPaint] Add your own custom painting code here..
  87. //[/UserPaint]
  88. }
  89. void ConfigSubscriptions::resized()
  90. {
  91. subscribeButton->setBounds (20, 20, 74, 16);
  92. ignoreButton->setBounds (98, 20, 74, 16);
  93. bansLabel->setBounds (20, 44, 152, 16);
  94. subscriptionsViewport->setBounds (24, 68, 144, 76);
  95. //[UserResized] Add your own custom resize handling here..
  96. //[/UserResized]
  97. }
  98. void ConfigSubscriptions::buttonClicked (Button* buttonThatWasClicked)
  99. {
  100. //[UserbuttonClicked_Pre]
  101. //[/UserbuttonClicked_Pre]
  102. if (buttonThatWasClicked == subscribeButton)
  103. {
  104. //[UserButtonCode_subscribeButton] -- add your button handler code here..
  105. //[/UserButtonCode_subscribeButton]
  106. }
  107. else if (buttonThatWasClicked == ignoreButton)
  108. {
  109. //[UserButtonCode_ignoreButton] -- add your button handler code here..
  110. //[/UserButtonCode_ignoreButton]
  111. }
  112. //[UserbuttonClicked_Post]
  113. bool should_subscribe = this->subscribeButton->getToggleState() ;
  114. bool should_ignore = this->ignoreButton->getToggleState() ;
  115. int subscribe_mode = (should_ignore) ? NJClient::SUBSCRIBE_DENY :
  116. (should_subscribe)? NJClient::SUBSCRIBE_ALL :
  117. NJClient::SUBSCRIBE_NONE ;
  118. setConfig(CONFIG::SUBSCRIBE_MODE_KEY , var(subscribe_mode)) ;
  119. //[/UserbuttonClicked_Post]
  120. }
  121. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  122. void ConfigSubscriptions::setConfig(Identifier a_key , var a_value)
  123. {
  124. this->configStore.setProperty(a_key , a_value , nullptr) ;
  125. }
  126. //[/MiscUserCode]
  127. //==============================================================================
  128. #if 0
  129. /* -- Introjucer information section --
  130. This is where the Introjucer stores the metadata that describe this GUI layout, so
  131. make changes in here at your peril!
  132. BEGIN_JUCER_METADATA
  133. <JUCER_COMPONENT documentType="Component" className="ConfigSubscriptions" componentName=""
  134. parentClasses="public Component" constructorParams="ValueTree config_store"
  135. variableInitialisers="configStore(config_store)" snapPixels="8"
  136. snapActive="1" snapShown="1" overlayOpacity="0.330" fixedSize="1"
  137. initialWidth="614" initialHeight="434">
  138. <BACKGROUND backgroundColour="0">
  139. <ROUNDRECT pos="0 0 192 172" cornerSize="10" fill="solid: ff200000" hasStroke="0"/>
  140. <ROUNDRECT pos="20 64 152 84" cornerSize="10" fill="solid: ff101010" hasStroke="1"
  141. stroke="1, mitered, butt" strokeColour="solid: ffffffff"/>
  142. </BACKGROUND>
  143. <TOGGLEBUTTON name="subscribeButton" id="a9eb5bfc0df5b172" memberName="subscribeButton"
  144. virtualName="" explicitFocusOrder="1" pos="20 20 74 16" txtcol="ffffffff"
  145. buttonText="auto-receive" connectedEdges="0" needsCallback="1"
  146. radioGroupId="0" state="1"/>
  147. <TOGGLEBUTTON name="ignoreButton" id="fdc09180d037febb" memberName="ignoreButton"
  148. virtualName="" explicitFocusOrder="2" pos="98 20 74 16" txtcol="ffffffff"
  149. buttonText="auto-ignore" connectedEdges="0" needsCallback="1"
  150. radioGroupId="0" state="1"/>
  151. <LABEL name="bansLabel" id="a67b459c94aba72e" memberName="bansLabel"
  152. virtualName="" explicitFocusOrder="0" pos="20 44 152 16" textCol="ffffffff"
  153. edTextCol="ff000000" edBkgCol="0" labelText="ignored users" editableSingleClick="0"
  154. editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
  155. fontsize="15" bold="0" italic="0" justification="12"/>
  156. <VIEWPORT name="subscriptionsViewport" id="1da1a4f83d3dffa2" memberName="subscriptionsViewport"
  157. virtualName="" explicitFocusOrder="3" pos="24 68 144 76" vscroll="1"
  158. hscroll="0" scrollbarThickness="12" contentType="2" jucerFile=""
  159. contentClass="Subscriptions" constructorParams="config_store"/>
  160. </JUCER_COMPONENT>
  161. END_JUCER_METADATA
  162. */
  163. #endif
  164. //[EndFile] You can add extra defines here...
  165. //[/EndFile]