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

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