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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 dagger.Module;
  50. import dagger.ObjectGraph;
  51. import dagger.Provides;
  52. import java.util.concurrent.ExecutorService;
  53. import javax.inject.Named;
  54. import javax.inject.Provider;
  55. import javax.inject.Singleton;
  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. /** The object graph to inject where necessary. */
  76. private ObjectGraph objectGraph;
  77. @Provides
  78. public ConnectionManager getConnectionManager(final ServerManager serverManager) {
  79. return serverManager;
  80. }
  81. @Provides
  82. @Named("errors")
  83. public ExecutorService getExecutorService() {
  84. return new LoggingExecutorService(1, 1, "Error Logging");
  85. }
  86. @Provides
  87. @Singleton
  88. public EventBus getMBassador() {
  89. return new DMDircMBassador();
  90. }
  91. @Provides
  92. public LifecycleController getLifecycleController(final SystemLifecycleController controller) {
  93. return controller;
  94. }
  95. @Provides
  96. @Singleton
  97. public CommandManager getCommandManager(
  98. final ConnectionManager connectionManager,
  99. final Provider<GlobalWindow> globalWindowProvider,
  100. @GlobalConfig final AggregateConfigProvider globalConfig) {
  101. final CommandManager manager = new CommandManager(connectionManager, globalWindowProvider);
  102. manager.initialise(globalConfig);
  103. return manager;
  104. }
  105. @Provides
  106. public CommandController getCommandController(final CommandManager commandManager) {
  107. return commandManager;
  108. }
  109. @Provides
  110. @Singleton
  111. public ThemeManager getThemeManager(
  112. final EventBus eventBus,
  113. final IdentityController controller,
  114. @Directory(DirectoryType.THEMES) final String directory) {
  115. final ThemeManager manager = new ThemeManager(controller, directory);
  116. manager.refreshAndLoadThemes();
  117. return manager;
  118. }
  119. @Provides
  120. @Singleton
  121. @GlobalConfig
  122. public ColourManager getGlobalColourManager(final ColourManagerFactory colourManagerFactory,
  123. @GlobalConfig final AggregateConfigProvider globalConfig) {
  124. return colourManagerFactory.getColourManager(globalConfig);
  125. }
  126. @Provides
  127. public ConnectionFactory getServerFactory(final ConnectionManager connectionManager) {
  128. return connectionManager;
  129. }
  130. @Provides
  131. public Downloader getDownloader() {
  132. return new Downloader();
  133. }
  134. /**
  135. * Sets the object graph that will be injected. Must be called before any provider method.
  136. *
  137. * @param objectGraph The object graph to inject.
  138. */
  139. public void setObjectGraph(final ObjectGraph objectGraph) {
  140. this.objectGraph = objectGraph;
  141. }
  142. @Provides
  143. @Singleton
  144. public ObjectGraph getObjectGraph() {
  145. return objectGraph;
  146. }
  147. }