Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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