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

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