Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ClientModule.java 5.7KB

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