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.

ClientModule.java 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (c) 2006-2014 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;
  23. import com.dmdirc.actions.ActionFactory;
  24. import com.dmdirc.actions.ActionGroup;
  25. import com.dmdirc.actions.ActionManager;
  26. import com.dmdirc.actions.wrappers.PerformWrapper;
  27. import com.dmdirc.commandline.CommandLineOptionsModule;
  28. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  29. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  30. import com.dmdirc.commandline.CommandLineParser;
  31. import com.dmdirc.commandparser.CommandManager;
  32. import com.dmdirc.commandparser.aliases.AliasesModule;
  33. import com.dmdirc.commandparser.auto.AutoCommandModule;
  34. import com.dmdirc.commandparser.commands.CommandModule;
  35. import com.dmdirc.config.ConfigModule;
  36. import com.dmdirc.interfaces.ActionController;
  37. import com.dmdirc.interfaces.CommandController;
  38. import com.dmdirc.interfaces.ConnectionFactory;
  39. import com.dmdirc.interfaces.ConnectionManager;
  40. import com.dmdirc.interfaces.LifecycleController;
  41. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  42. import com.dmdirc.interfaces.config.IdentityController;
  43. import com.dmdirc.messages.MessagesModule;
  44. import com.dmdirc.plugins.PluginModule;
  45. import com.dmdirc.ui.IconManager;
  46. import com.dmdirc.ui.messages.ColourManager;
  47. import com.dmdirc.ui.messages.ColourManagerFactory;
  48. import com.dmdirc.ui.themes.ThemeManager;
  49. import com.dmdirc.updater.UpdaterModule;
  50. import com.dmdirc.updater.manager.UpdateManager;
  51. import com.dmdirc.util.URLBuilder;
  52. import com.dmdirc.util.io.Downloader;
  53. import java.util.Set;
  54. import javax.inject.Provider;
  55. import javax.inject.Qualifier;
  56. import javax.inject.Singleton;
  57. import dagger.Module;
  58. import dagger.ObjectGraph;
  59. import dagger.Provides;
  60. /**
  61. * Provides dependencies for the client.
  62. */
  63. @SuppressWarnings("TypeMayBeWeakened")
  64. @Module(
  65. injects = {Main.class, CommandLineParser.class},
  66. includes = {
  67. AliasesModule.class,
  68. AutoCommandModule.class,
  69. CommandLineOptionsModule.class,
  70. CommandModule.class,
  71. ConfigModule.class,
  72. MessagesModule.class,
  73. PluginModule.class,
  74. UpdaterModule.class
  75. },
  76. library = true)
  77. public class ClientModule {
  78. /** Qualifier that identities a global configuration source. */
  79. @Qualifier
  80. public @interface GlobalConfig {
  81. }
  82. /** Qualifier that identities the user settings config provider. */
  83. @Qualifier
  84. public @interface UserConfig {
  85. }
  86. /** Qualifier that identities the addon defaults config provider. */
  87. @Qualifier
  88. public @interface AddonConfig {
  89. }
  90. /** The object graph to inject where necessary. */
  91. private ObjectGraph objectGraph;
  92. @Provides
  93. public ConnectionManager getConnectionManager(final ServerManager serverManager) {
  94. return serverManager;
  95. }
  96. @Provides
  97. @Singleton
  98. public DMDircMBassador getMBassador() {
  99. return new DMDircMBassador();
  100. }
  101. @Provides
  102. @GlobalConfig
  103. @Singleton
  104. public IconManager getGlobalIconManager(
  105. @GlobalConfig final AggregateConfigProvider globalConfig,
  106. final URLBuilder urlBuilder) {
  107. return new IconManager(globalConfig, urlBuilder);
  108. }
  109. @Provides
  110. @Singleton
  111. public ActionManager getActionManager(
  112. final IdentityController identityController,
  113. final ActionFactory actionFactory,
  114. final Provider<Set<ActionGroup>> actionWrappersProvider,
  115. final Provider<UpdateManager> updateManagerProvider,
  116. final DMDircMBassador eventBus,
  117. @Directory(DirectoryType.ACTIONS) final String directory) {
  118. final ActionManager actionManager = new ActionManager(identityController,
  119. actionFactory, actionWrappersProvider, updateManagerProvider, eventBus, directory);
  120. ActionManager.setActionManager(actionManager);
  121. return actionManager;
  122. }
  123. @Provides
  124. public ActionController getActionController(final ActionManager actionManager) {
  125. return actionManager;
  126. }
  127. @Provides
  128. public LifecycleController getLifecycleController(final SystemLifecycleController controller) {
  129. return controller;
  130. }
  131. @Provides
  132. @Singleton
  133. public CommandManager getCommandManager(
  134. final ConnectionManager connectionManager,
  135. @GlobalConfig final AggregateConfigProvider globalConfig) {
  136. final CommandManager manager = new CommandManager(connectionManager);
  137. manager.initialise(globalConfig);
  138. return manager;
  139. }
  140. @Provides
  141. public CommandController getCommandController(final CommandManager commandManager) {
  142. return commandManager;
  143. }
  144. @Provides
  145. @Singleton
  146. public ThemeManager getThemeManager(
  147. final DMDircMBassador eventBus,
  148. final IdentityController controller,
  149. @Directory(DirectoryType.THEMES) final String directory) {
  150. final ThemeManager manager = new ThemeManager(eventBus, controller, directory);
  151. manager.refreshAndLoadThemes();
  152. return manager;
  153. }
  154. @Provides(type = Provides.Type.SET)
  155. @Singleton
  156. public ActionGroup getPerformWrapper(final PerformWrapper wrapper) {
  157. return wrapper;
  158. }
  159. @Provides
  160. @Singleton
  161. @GlobalConfig
  162. public ColourManager getGlobalColourManager(final ColourManagerFactory colourManagerFactory,
  163. @GlobalConfig final AggregateConfigProvider globalConfig) {
  164. return colourManagerFactory.getColourManager(globalConfig);
  165. }
  166. @Provides
  167. public ConnectionFactory getServerFactory(final ConnectionManager connectionManager) {
  168. return connectionManager;
  169. }
  170. @Provides
  171. public Downloader getDownloader() {
  172. return new Downloader();
  173. }
  174. /**
  175. * Sets the object graph that will be injected. Must be called before any provider method.
  176. *
  177. * @param objectGraph The object graph to inject.
  178. */
  179. public void setObjectGraph(final ObjectGraph objectGraph) {
  180. this.objectGraph = objectGraph;
  181. }
  182. @Provides
  183. @Singleton
  184. public ObjectGraph getObjectGraph() {
  185. return objectGraph;
  186. }
  187. }