123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- /*
- * Copyright (c) 2006-2015 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc;
-
- import com.dmdirc.commandline.CommandLineOptionsModule;
- import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
- import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
- import com.dmdirc.commandline.CommandLineParser;
- import com.dmdirc.commandparser.CommandManager;
- import com.dmdirc.commandparser.aliases.AliasesModule;
- import com.dmdirc.commandparser.auto.AutoCommandModule;
- import com.dmdirc.commandparser.commands.CommandModule;
- import com.dmdirc.config.ConfigModule;
- import com.dmdirc.config.GlobalConfig;
- import com.dmdirc.config.profiles.ProfilesModule;
- import com.dmdirc.interfaces.CommandController;
- import com.dmdirc.interfaces.ConnectionFactory;
- import com.dmdirc.interfaces.ConnectionManager;
- import com.dmdirc.interfaces.EventBus;
- import com.dmdirc.interfaces.LifecycleController;
- import com.dmdirc.interfaces.config.AggregateConfigProvider;
- import com.dmdirc.interfaces.config.IdentityController;
- import com.dmdirc.plugins.PluginModule;
- import com.dmdirc.ui.messages.ColourManager;
- import com.dmdirc.ui.messages.ColourManagerFactory;
- import com.dmdirc.ui.messages.UiMessagesModule;
- import com.dmdirc.ui.themes.ThemeManager;
- import com.dmdirc.updater.UpdaterModule;
- import com.dmdirc.util.LoggingExecutorService;
- import com.dmdirc.util.io.Downloader;
- import dagger.Module;
- import dagger.ObjectGraph;
- import dagger.Provides;
- import java.util.concurrent.ExecutorService;
- import javax.inject.Named;
- import javax.inject.Provider;
- import javax.inject.Singleton;
-
- /**
- * Provides dependencies for the client.
- */
- @SuppressWarnings("TypeMayBeWeakened")
- @Module(
- injects = {Main.class, CommandLineParser.class},
- includes = {
- AliasesModule.class,
- AutoCommandModule.class,
- CommandLineOptionsModule.class,
- CommandModule.class,
- ConfigModule.class,
- PluginModule.class,
- ProfilesModule.class,
- UiMessagesModule.class,
- UpdaterModule.class
- },
- library = true)
- public class ClientModule {
-
- /** The object graph to inject where necessary. */
- private ObjectGraph objectGraph;
-
- @Provides
- public ConnectionManager getConnectionManager(final ServerManager serverManager) {
- return serverManager;
- }
-
- @Provides
- @Named("errors")
- public ExecutorService getExecutorService() {
- return new LoggingExecutorService(1, 1, "Error Logging");
- }
-
- @Provides
- @Singleton
- public EventBus getMBassador() {
- return new DMDircMBassador();
- }
-
- @Provides
- public LifecycleController getLifecycleController(final SystemLifecycleController controller) {
- return controller;
- }
-
- @Provides
- @Singleton
- public CommandManager getCommandManager(
- final ConnectionManager connectionManager,
- final Provider<GlobalWindow> globalWindowProvider,
- @GlobalConfig final AggregateConfigProvider globalConfig) {
- final CommandManager manager = new CommandManager(connectionManager, globalWindowProvider);
- manager.initialise(globalConfig);
- return manager;
- }
-
- @Provides
- public CommandController getCommandController(final CommandManager commandManager) {
- return commandManager;
- }
-
- @Provides
- @Singleton
- public ThemeManager getThemeManager(
- final EventBus eventBus,
- final IdentityController controller,
- @Directory(DirectoryType.THEMES) final String directory) {
- final ThemeManager manager = new ThemeManager(controller, directory);
- manager.refreshAndLoadThemes();
- return manager;
- }
-
- @Provides
- @Singleton
- @GlobalConfig
- public ColourManager getGlobalColourManager(final ColourManagerFactory colourManagerFactory,
- @GlobalConfig final AggregateConfigProvider globalConfig) {
- return colourManagerFactory.getColourManager(globalConfig);
- }
-
- @Provides
- public ConnectionFactory getServerFactory(final ConnectionManager connectionManager) {
- return connectionManager;
- }
-
- @Provides
- public Downloader getDownloader() {
- return new Downloader();
- }
-
- /**
- * Sets the object graph that will be injected. Must be called before any provider method.
- *
- * @param objectGraph The object graph to inject.
- */
- public void setObjectGraph(final ObjectGraph objectGraph) {
- this.objectGraph = objectGraph;
- }
-
- @Provides
- @Singleton
- public ObjectGraph getObjectGraph() {
- return objectGraph;
- }
-
- }
|