You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PreferencesManager.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.config.prefs;
  23. import com.dmdirc.events.ConnectionPrefsRequestedEvent;
  24. import com.dmdirc.events.GroupChatPrefsRequestedEvent;
  25. import com.dmdirc.interfaces.EventBus;
  26. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  27. import com.dmdirc.interfaces.config.ConfigProvider;
  28. import com.dmdirc.util.validators.NumericalValidator;
  29. import com.dmdirc.util.validators.OptionalValidator;
  30. import javax.inject.Inject;
  31. /**
  32. * Manages preferences for the client.
  33. *
  34. * @since 0.6.5
  35. */
  36. public class PreferencesManager {
  37. /** Event bus to public events on. */
  38. private final EventBus eventBus;
  39. @Inject
  40. public PreferencesManager(final EventBus eventBus) {
  41. this.eventBus = eventBus;
  42. }
  43. /**
  44. * Retrieves a category containing preferences settings which should be displayed in
  45. * channel-specific contexts.
  46. *
  47. * @param manager The config manager to load settings from
  48. * @param identity The identity to save settings to
  49. *
  50. * @return A preferences category populated with channel settings
  51. */
  52. public PreferencesCategory getServerSettings(final AggregateConfigProvider manager,
  53. final ConfigProvider identity) {
  54. final PreferencesCategory category = new PreferencesCategory("Server settings",
  55. "These settings are specific to this server on this network,"
  56. + " any settings specified here will overwrite global settings");
  57. // Copy all the channel ones
  58. getChannelSettings(manager, identity).getSettings().forEach(category::addSetting);
  59. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  60. "general", "closechannelsonquit", "Close channels on quit",
  61. "Close channel windows when you manually disconnect from the server",
  62. manager, identity));
  63. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  64. "general", "closechannelsondisconnect",
  65. "Close channels on disconnect", "Close channel windows when "
  66. + "the server is disconnected (because of an error)",
  67. manager, identity));
  68. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  69. "general", "closequeriesonquit", "Close queries on quit",
  70. "Close query windows when you manually disconnect from the server",
  71. manager, identity));
  72. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  73. "general", "closequeriesondisconnect",
  74. "Close queries on disconnect", "Close query windows when "
  75. + "the server is disconnected (because of an error)",
  76. manager, identity));
  77. category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
  78. "server", "pingtimer", "Ping warning time",
  79. "How long to wait after a ping reply is sent before showing "
  80. + "a warning message",
  81. manager, identity));
  82. category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
  83. "server", "pingtimeout", "Ping timeout",
  84. "How long to wait for a server to reply to a PING request "
  85. + "before assuming the server has died",
  86. manager, identity));
  87. category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
  88. "server", "pingfrequency", "Ping frequency",
  89. "How often a PING request should be sent to the server (to "
  90. + "check that it is still alive)",
  91. manager, identity));
  92. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  93. "general", "reconnectonconnectfailure", "Reconnect on failure",
  94. "Attempt to reconnect if there is an error when connecting",
  95. manager, identity));
  96. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  97. "general", "reconnectondisconnect", "Reconnect on disconnect",
  98. "Attempt to reconnect if the server is disconnected",
  99. manager, identity));
  100. category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
  101. "general", "reconnectdelay", "Reconnect delay",
  102. "How long to wait before attempting to reconnect to a server",
  103. manager, identity));
  104. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  105. "general", "rejoinchannels", "Rejoin open channels",
  106. "Rejoin open channels when reconnecting to a server",
  107. manager, identity));
  108. category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  109. "general", "quitmessage",
  110. "Quit message", "Default quit message to use when disconnecting",
  111. manager, identity));
  112. category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  113. "general", "reconnectmessage",
  114. "Reconnect message", "Default quit message to use when reconnecting",
  115. manager, identity));
  116. eventBus.publish(new ConnectionPrefsRequestedEvent(category, manager, identity));
  117. return category;
  118. }
  119. /**
  120. * Retrieves a category containing preferences settings which should be displayed in
  121. * channel-specific contexts.
  122. *
  123. * @param manager The config manager to load settings from
  124. * @param identity The identity to save settings to
  125. *
  126. * @return A preferences category populated with channel settings
  127. */
  128. public PreferencesCategory getChannelSettings(final AggregateConfigProvider manager,
  129. final ConfigProvider identity) {
  130. final PreferencesCategory category = new PreferencesCategory("Channel settings",
  131. "These settings are specific to this channel on this network,"
  132. + " any settings specified here will overwrite global settings");
  133. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  134. "channel", "showmodeprefix", "Show mode prefix",
  135. "Prefix users' names with their mode (e.g. @) in channels",
  136. manager, identity));
  137. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  138. "ui", "shownickcoloursintext", "Show nick colours in text area",
  139. "Show nickname colours (if set) in text areas",
  140. manager, identity));
  141. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  142. "ui", "shownickcoloursinnicklist", "Show nick colours in nicklists",
  143. "Show nickname colours (if set) in channel nicklists",
  144. manager, identity));
  145. category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  146. "general", "partmessage",
  147. "Part message", "Default part message to use when leaving channels",
  148. manager, identity));
  149. category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  150. "general", "cyclemessage",
  151. "Cycle message", "Default part message to use when cycling channels",
  152. manager, identity));
  153. category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
  154. "general", "kickmessage",
  155. "Kick message", "Default message to use when kicking people",
  156. manager, identity));
  157. category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
  158. "ui", "backgroundcolour", "Background colour", "Default "
  159. + "background colour to use",
  160. manager, identity));
  161. category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
  162. "ui", "foregroundcolour", "Foreground colour", "Default "
  163. + "foreground colour to use",
  164. manager, identity));
  165. category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
  166. "ui", "inputbackgroundcolour", "Input background colour",
  167. "Default background colour to use for input fields",
  168. manager, identity));
  169. category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
  170. "ui", "inputforegroundcolour", "Input foreground colour",
  171. "Default foreground colour to use for input fields",
  172. manager, identity));
  173. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  174. "general", "showcolourdialog", "Show colour dialog",
  175. "Show colour picker dialog when using colour control codes",
  176. manager, identity));
  177. category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
  178. "ui", "nicklistbackgroundcolour", "Nicklist background colour",
  179. "Background colour to use for the nicklist",
  180. manager, identity));
  181. category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
  182. "ui", "nicklistforegroundcolour", "Nicklist foreground colour",
  183. "Foreground colour to use for the nicklist",
  184. manager, identity));
  185. category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
  186. "ui", "nickListAltBackgroundColour",
  187. "Alternate background colour",
  188. "Background colour to use for every other nicklist entry",
  189. manager, identity));
  190. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  191. "nicklist", "sortByMode", "Sort nicklist by user mode",
  192. "Sort nicknames by the modes that they have?",
  193. manager, identity));
  194. category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  195. "nicklist", "sortByCase", "Sort nicklist by case",
  196. "Sort nicknames in a case-sensitive manner?",
  197. manager, identity));
  198. category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALINTEGER,
  199. new OptionalValidator(new NumericalValidator(10, -1)),
  200. "ui", "frameBufferSize", "Window buffer size",
  201. "The maximum number of lines in a window buffer",
  202. manager, identity));
  203. category.addSetting(new PreferencesSetting(PreferencesType.FONT,
  204. "ui", "textPaneFontName", "Textpane font",
  205. "Font for the textpane",
  206. manager, identity));
  207. category.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  208. "ui", "textPaneFontSize", "Textpane font size",
  209. "Font size for the textpane",
  210. manager, identity));
  211. category.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  212. "ui", "inputbuffersize", "Input buffer size",
  213. "Number of items of input history to keep",
  214. manager, identity));
  215. eventBus.publish(new GroupChatPrefsRequestedEvent(category, manager, identity));
  216. return category;
  217. }
  218. }