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.

FeedbackHelper.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.ui.core.feedback;
  18. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  19. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  20. import com.dmdirc.config.GlobalConfig;
  21. import com.dmdirc.interfaces.Connection;
  22. import com.dmdirc.interfaces.ConnectionManager;
  23. import com.dmdirc.config.provider.AggregateConfigProvider;
  24. import com.dmdirc.parser.interfaces.Parser;
  25. import com.dmdirc.util.ClientInfo;
  26. import javax.inject.Inject;
  27. import java.nio.file.Path;
  28. public class FeedbackHelper {
  29. private final Path configDirectory;
  30. private final ClientInfo clientInfo;
  31. private final ConnectionManager connectionManager;
  32. private final AggregateConfigProvider config;
  33. @Inject
  34. public FeedbackHelper(@Directory(DirectoryType.BASE) final Path configDirectory,
  35. final ClientInfo clientInfo, final ConnectionManager connectionManager,
  36. @GlobalConfig final AggregateConfigProvider config) {
  37. this.configDirectory = configDirectory;
  38. this.clientInfo = clientInfo;
  39. this.connectionManager = connectionManager;
  40. this.config = config;
  41. }
  42. public String getDMDircInfo() {
  43. return "DMDirc version: " + clientInfo.getVersionInformation() + '\n'
  44. + "Profile directory: " + configDirectory + '\n' + "Java version: "
  45. + clientInfo.getJavaInformation() + '\n' + "OS Version: "
  46. + clientInfo.getOperatingSystemInformation();
  47. }
  48. public String getServerInfo() {
  49. final StringBuilder serverInfo = new StringBuilder(255);
  50. connectionManager.getConnections()
  51. .forEach(c -> serverInfo.append(getServerInfo(c)).append('\n'));
  52. return serverInfo.toString();
  53. }
  54. public String getServerInfo(final Connection connection) {
  55. if (connection.getState().isDisconnected()) {
  56. return "";
  57. }
  58. final Parser parser = connection.getParser().get();
  59. return "Actual name: " + parser.getServerName() + '\n'
  60. + "Network: " + connection.getNetwork() + '\n'
  61. + "IRCd: " + parser.getServerSoftware() + " - "
  62. + parser.getServerSoftwareType() + '\n'
  63. + "Modes: " + parser.getBooleanChannelModes() + ' '
  64. + parser.getListChannelModes() + ' '
  65. + parser.getParameterChannelModes() + ' '
  66. + parser.getDoubleParameterChannelModes();
  67. }
  68. public String getVersion() {
  69. return config.getOption("version", "version");
  70. }
  71. }