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

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