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 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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;
  23. import com.dmdirc.commandline.CommandLineOptionsModule;
  24. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  25. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  26. import com.dmdirc.commandline.CommandLineParser;
  27. import com.dmdirc.commandparser.CommandManager;
  28. import com.dmdirc.commandparser.aliases.AliasesModule;
  29. import com.dmdirc.commandparser.auto.AutoCommandModule;
  30. import com.dmdirc.commandparser.commands.CommandModule;
  31. import com.dmdirc.config.ConfigModule;
  32. import com.dmdirc.config.profiles.ProfilesModule;
  33. import com.dmdirc.interfaces.CommandController;
  34. import com.dmdirc.interfaces.ConnectionFactory;
  35. import com.dmdirc.interfaces.ConnectionManager;
  36. import com.dmdirc.interfaces.EventBus;
  37. import com.dmdirc.interfaces.LifecycleController;
  38. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  39. import com.dmdirc.interfaces.config.IdentityController;
  40. import com.dmdirc.plugins.PluginModule;
  41. import com.dmdirc.ui.messages.ColourManager;
  42. import com.dmdirc.ui.messages.ColourManagerFactory;
  43. import com.dmdirc.ui.messages.UiMessagesModule;
  44. import com.dmdirc.ui.themes.ThemeManager;
  45. import com.dmdirc.updater.UpdaterModule;
  46. import com.dmdirc.util.LoggingExecutorService;
  47. import com.dmdirc.util.io.Downloader;
  48. import java.util.concurrent.ExecutorService;
  49. import javax.inject.Named;
  50. import javax.inject.Provider;
  51. import javax.inject.Qualifier;
  52. import javax.inject.Singleton;
  53. import dagger.Module;
  54. import dagger.ObjectGraph;
  55. import dagger.Provides;
  56. /**
  57. * Provides dependencies for the client.
  58. */
  59. @SuppressWarnings("TypeMayBeWeakened")
  60. @Module(
  61. injects = {Main.class, CommandLineParser.class},
  62. includes = {
  63. AliasesModule.class,
  64. AutoCommandModule.class,
  65. CommandLineOptionsModule.class,
  66. CommandModule.class,
  67. ConfigModule.class,
  68. PluginModule.class,
  69. ProfilesModule.class,
  70. UiMessagesModule.class,
  71. UpdaterModule.class
  72. },
  73. library = true)
  74. public class ClientModule {
  75. /** Qualifier that identities a global configuration source. */
  76. @Qualifier
  77. public @interface GlobalConfig {
  78. }
  79. /** Qualifier that identities the user settings config provider. */
  80. @Qualifier
  81. public @interface UserConfig {
  82. }
  83. /** Qualifier that identities the addon defaults config provider. */
  84. @Qualifier
  85. public @interface AddonConfig {
  86. }
  87. /** The object graph to inject where necessary. */
  88. private ObjectGraph objectGraph;
  89. @Provides
  90. public ConnectionManager getConnectionManager(final ServerManager serverManager) {
  91. return serverManager;
  92. }
  93. @Provides
  94. @Named("errors")
  95. public ExecutorService getExecutorService() {
  96. return new LoggingExecutorService(1, 1, "Error Logging");
  97. }
  98. @Provides
  99. @Singleton
  100. public EventBus getMBassador() {
  101. return new DMDircMBassador();
  102. }
  103. @Provides
  104. public LifecycleController getLifecycleController(final SystemLifecycleController controller) {
  105. return controller;
  106. }
  107. @Provides
  108. @Singleton
  109. public CommandManager getCommandManager(
  110. final ConnectionManager connectionManager,
  111. final Provider<GlobalWindow> globalWindowProvider,
  112. @GlobalConfig final AggregateConfigProvider globalConfig) {
  113. final CommandManager manager = new CommandManager(connectionManager, globalWindowProvider);
  114. manager.initialise(globalConfig);
  115. return manager;
  116. }
  117. @Provides
  118. public CommandController getCommandController(final CommandManager commandManager) {
  119. return commandManager;
  120. }
  121. @Provides
  122. @Singleton
  123. public ThemeManager getThemeManager(
  124. final EventBus eventBus,
  125. final IdentityController controller,
  126. @Directory(DirectoryType.THEMES) final String directory) {
  127. final ThemeManager manager = new ThemeManager(controller, directory);
  128. manager.refreshAndLoadThemes();
  129. return manager;
  130. }
  131. @Provides
  132. @Singleton
  133. @GlobalConfig
  134. public ColourManager getGlobalColourManager(final ColourManagerFactory colourManagerFactory,
  135. @GlobalConfig final AggregateConfigProvider globalConfig) {
  136. return colourManagerFactory.getColourManager(globalConfig);
  137. }
  138. @Provides
  139. public ConnectionFactory getServerFactory(final ConnectionManager connectionManager) {
  140. return connectionManager;
  141. }
  142. @Provides
  143. public Downloader getDownloader() {
  144. return new Downloader();
  145. }
  146. /**
  147. * Sets the object graph that will be injected. Must be called before any provider method.
  148. *
  149. * @param objectGraph The object graph to inject.
  150. */
  151. public void setObjectGraph(final ObjectGraph objectGraph) {
  152. this.objectGraph = objectGraph;
  153. }
  154. @Provides
  155. @Singleton
  156. public ObjectGraph getObjectGraph() {
  157. return objectGraph;
  158. }
  159. }