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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.LifecycleController;
  37. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  38. import com.dmdirc.interfaces.config.IdentityController;
  39. import com.dmdirc.plugins.PluginModule;
  40. import com.dmdirc.ui.messages.ColourManager;
  41. import com.dmdirc.ui.messages.ColourManagerFactory;
  42. import com.dmdirc.ui.messages.UiMessagesModule;
  43. import com.dmdirc.ui.messages.sink.MessagesModule;
  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. MessagesModule.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 a global configuration source. */
  77. @Qualifier
  78. public @interface GlobalConfig {
  79. }
  80. /** Qualifier that identities the user settings config provider. */
  81. @Qualifier
  82. public @interface UserConfig {
  83. }
  84. /** Qualifier that identities the addon defaults config provider. */
  85. @Qualifier
  86. public @interface AddonConfig {
  87. }
  88. /** The object graph to inject where necessary. */
  89. private ObjectGraph objectGraph;
  90. @Provides
  91. public ConnectionManager getConnectionManager(final ServerManager serverManager) {
  92. return serverManager;
  93. }
  94. @Provides
  95. @Named("errors")
  96. public ExecutorService getExecutorService() {
  97. return new LoggingExecutorService(1, 1, "Error Logging");
  98. }
  99. @Provides
  100. @Singleton
  101. public DMDircMBassador getMBassador() {
  102. return new DMDircMBassador();
  103. }
  104. @Provides
  105. public LifecycleController getLifecycleController(final SystemLifecycleController controller) {
  106. return controller;
  107. }
  108. @Provides
  109. @Singleton
  110. public CommandManager getCommandManager(
  111. final ConnectionManager connectionManager,
  112. final Provider<GlobalWindow> globalWindowProvider,
  113. @GlobalConfig final AggregateConfigProvider globalConfig) {
  114. final CommandManager manager = new CommandManager(connectionManager, globalWindowProvider);
  115. manager.initialise(globalConfig);
  116. return manager;
  117. }
  118. @Provides
  119. public CommandController getCommandController(final CommandManager commandManager) {
  120. return commandManager;
  121. }
  122. @Provides
  123. @Singleton
  124. public ThemeManager getThemeManager(
  125. final DMDircMBassador eventBus,
  126. final IdentityController controller,
  127. @Directory(DirectoryType.THEMES) final String directory) {
  128. final ThemeManager manager = new ThemeManager(controller, directory);
  129. manager.refreshAndLoadThemes();
  130. return manager;
  131. }
  132. @Provides
  133. @Singleton
  134. @GlobalConfig
  135. public ColourManager getGlobalColourManager(final ColourManagerFactory colourManagerFactory,
  136. @GlobalConfig final AggregateConfigProvider globalConfig) {
  137. return colourManagerFactory.getColourManager(globalConfig);
  138. }
  139. @Provides
  140. public ConnectionFactory getServerFactory(final ConnectionManager connectionManager) {
  141. return connectionManager;
  142. }
  143. @Provides
  144. public Downloader getDownloader() {
  145. return new Downloader();
  146. }
  147. /**
  148. * Sets the object graph that will be injected. Must be called before any provider method.
  149. *
  150. * @param objectGraph The object graph to inject.
  151. */
  152. public void setObjectGraph(final ObjectGraph objectGraph) {
  153. this.objectGraph = objectGraph;
  154. }
  155. @Provides
  156. @Singleton
  157. public ObjectGraph getObjectGraph() {
  158. return objectGraph;
  159. }
  160. }