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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc;
  18. import com.dmdirc.commandline.CommandLineOptionsModule;
  19. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  20. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  21. import com.dmdirc.commandline.CommandLineParser;
  22. import com.dmdirc.commandparser.CommandManager;
  23. import com.dmdirc.commandparser.aliases.AliasesModule;
  24. import com.dmdirc.commandparser.auto.AutoCommandModule;
  25. import com.dmdirc.commandparser.commands.CommandModule;
  26. import com.dmdirc.config.ConfigModule;
  27. import com.dmdirc.config.GlobalConfig;
  28. import com.dmdirc.config.profiles.ProfilesModule;
  29. import com.dmdirc.interfaces.CommandController;
  30. import com.dmdirc.interfaces.ConnectionFactory;
  31. import com.dmdirc.interfaces.ConnectionManager;
  32. import com.dmdirc.interfaces.EventBus;
  33. import com.dmdirc.interfaces.LifecycleController;
  34. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  35. import com.dmdirc.interfaces.config.IdentityController;
  36. import com.dmdirc.plugins.PluginModule;
  37. import com.dmdirc.ui.messages.ColourManager;
  38. import com.dmdirc.ui.messages.ColourManagerFactory;
  39. import com.dmdirc.ui.messages.UiMessagesModule;
  40. import com.dmdirc.ui.themes.ThemeManager;
  41. import com.dmdirc.updater.UpdaterModule;
  42. import com.dmdirc.util.LoggingExecutorService;
  43. import com.dmdirc.util.io.Downloader;
  44. import dagger.Module;
  45. import dagger.ObjectGraph;
  46. import dagger.Provides;
  47. import java.util.concurrent.ExecutorService;
  48. import javax.inject.Named;
  49. import javax.inject.Provider;
  50. import javax.inject.Singleton;
  51. /**
  52. * Provides dependencies for the client.
  53. */
  54. @SuppressWarnings("TypeMayBeWeakened")
  55. @Module(
  56. injects = {Main.class, CommandLineParser.class},
  57. includes = {
  58. AliasesModule.class,
  59. AutoCommandModule.class,
  60. CommandLineOptionsModule.class,
  61. CommandModule.class,
  62. ConfigModule.class,
  63. PluginModule.class,
  64. ProfilesModule.class,
  65. UiMessagesModule.class,
  66. UpdaterModule.class
  67. },
  68. library = true)
  69. public class ClientModule {
  70. /** The object graph to inject where necessary. */
  71. private ObjectGraph objectGraph;
  72. @Provides
  73. public ConnectionManager getConnectionManager(final ServerManager serverManager) {
  74. return serverManager;
  75. }
  76. @Provides
  77. @Named("errors")
  78. public ExecutorService getExecutorService() {
  79. return new LoggingExecutorService(1, 1, "Error Logging");
  80. }
  81. @Provides
  82. @Singleton
  83. public EventBus getMBassador() {
  84. return new DMDircMBassador();
  85. }
  86. @Provides
  87. public LifecycleController getLifecycleController(final SystemLifecycleController controller) {
  88. return controller;
  89. }
  90. @Provides
  91. @Singleton
  92. public CommandManager getCommandManager(
  93. final ConnectionManager connectionManager,
  94. final Provider<GlobalWindow> globalWindowProvider,
  95. @GlobalConfig final AggregateConfigProvider globalConfig) {
  96. final CommandManager manager = new CommandManager(connectionManager, globalWindowProvider);
  97. manager.initialise(globalConfig);
  98. return manager;
  99. }
  100. @Provides
  101. public CommandController getCommandController(final CommandManager commandManager) {
  102. return commandManager;
  103. }
  104. @Provides
  105. @Singleton
  106. public ThemeManager getThemeManager(
  107. final EventBus eventBus,
  108. final IdentityController controller,
  109. @Directory(DirectoryType.THEMES) final String directory) {
  110. final ThemeManager manager = new ThemeManager(controller, directory);
  111. manager.refreshAndLoadThemes();
  112. return manager;
  113. }
  114. @Provides
  115. @Singleton
  116. @GlobalConfig
  117. public ColourManager getGlobalColourManager(final ColourManagerFactory colourManagerFactory,
  118. @GlobalConfig final AggregateConfigProvider globalConfig) {
  119. return colourManagerFactory.getColourManager(globalConfig);
  120. }
  121. @Provides
  122. public ConnectionFactory getServerFactory(final ConnectionManager connectionManager) {
  123. return connectionManager;
  124. }
  125. @Provides
  126. public Downloader getDownloader() {
  127. return new Downloader();
  128. }
  129. /**
  130. * Sets the object graph that will be injected. Must be called before any provider method.
  131. *
  132. * @param objectGraph The object graph to inject.
  133. */
  134. public void setObjectGraph(final ObjectGraph objectGraph) {
  135. this.objectGraph = objectGraph;
  136. }
  137. @Provides
  138. @Singleton
  139. public ObjectGraph getObjectGraph() {
  140. return objectGraph;
  141. }
  142. }