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.

FeedbackDialog.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Copyright (c) 2006-2014 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.addons.ui_swing.dialogs;
  23. import com.dmdirc.ClientModule.GlobalConfig;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.ServerManager;
  26. import com.dmdirc.addons.ui_swing.MainFrame;
  27. import com.dmdirc.addons.ui_swing.SwingController;
  28. import com.dmdirc.addons.ui_swing.UIUtilities;
  29. import com.dmdirc.addons.ui_swing.components.SendWorker;
  30. import com.dmdirc.addons.ui_swing.components.text.TextLabel;
  31. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  32. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  33. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  34. import com.dmdirc.util.ClientInfo;
  35. import java.awt.Insets;
  36. import java.awt.event.ActionEvent;
  37. import java.awt.event.ActionListener;
  38. import javax.inject.Inject;
  39. import javax.swing.BorderFactory;
  40. import javax.swing.JButton;
  41. import javax.swing.JCheckBox;
  42. import javax.swing.JLabel;
  43. import javax.swing.JScrollPane;
  44. import javax.swing.JTextArea;
  45. import javax.swing.JTextField;
  46. import javax.swing.event.DocumentEvent;
  47. import javax.swing.event.DocumentListener;
  48. import net.miginfocom.swing.MigLayout;
  49. /** Feedback form. */
  50. public class FeedbackDialog extends StandardDialog implements ActionListener, DocumentListener {
  51. /** Serial version UID. */
  52. private static final long serialVersionUID = 1;
  53. /** Server manager. */
  54. private final ServerManager serverManager;
  55. /** Config. */
  56. private final AggregateConfigProvider config;
  57. /** Config directory. */
  58. private final String configDirectory;
  59. /** Information label. */
  60. private TextLabel info;
  61. /** Name field. */
  62. private JTextField name;
  63. /** Email field. */
  64. private JTextField email;
  65. /** Feedback area. */
  66. private JTextArea feedback;
  67. /** Server info checkbox. */
  68. private JCheckBox serverCheckbox;
  69. /** DMDirc info checkbox. */
  70. private JCheckBox dmdircCheckbox;
  71. /** Sent. */
  72. private boolean sentReport = false;
  73. /**
  74. * Instantiates the feedback dialog.
  75. *
  76. * @param parentWindow Parent window
  77. * @param serverManager Server manager
  78. * @param config Config
  79. * @param baseDirectory The base directory to include in feedback.
  80. */
  81. @Inject
  82. public FeedbackDialog(
  83. final MainFrame parentWindow,
  84. final ServerManager serverManager,
  85. @GlobalConfig final AggregateConfigProvider config,
  86. @Directory(DirectoryType.BASE) final String baseDirectory) {
  87. super(parentWindow, ModalityType.MODELESS);
  88. this.serverManager = serverManager;
  89. this.config = config;
  90. this.configDirectory = baseDirectory;
  91. initComponents();
  92. layoutComponents();
  93. addListeners();
  94. setTitle("Feedback");
  95. setResizable(false);
  96. }
  97. /** Initialises the components. */
  98. private void initComponents() {
  99. orderButtons(new JButton(), new JButton());
  100. getOkButton().setText("Send");
  101. getOkButton().setActionCommand("Send");
  102. getOkButton().setEnabled(false);
  103. getCancelButton().setActionCommand("Close");
  104. info = new TextLabel("Thank you for using DMDirc. If you have any "
  105. + "feedback about the client, such as bug reports or feature "
  106. + "requests, please send it to us using the form below. "
  107. + "The name and e-mail address fields are optional if you "
  108. + "don't want us to contact you about your feedback.\n\n"
  109. + "Please note that this is for feedback such as bug reports "
  110. + "and suggestions, not for technical support. For "
  111. + "technical support, please join #DMDirc using the button "
  112. + "in the help menu.");
  113. name = new JTextField();
  114. email = new JTextField();
  115. feedback = new JTextArea();
  116. serverCheckbox =
  117. new JCheckBox("Include information about connected servers.");
  118. dmdircCheckbox = new JCheckBox("Include information about DMDirc.");
  119. UIUtilities.addUndoManager(name);
  120. UIUtilities.addUndoManager(email);
  121. UIUtilities.addUndoManager(feedback);
  122. }
  123. /** Lays out the components. */
  124. private void layoutComponents() {
  125. serverCheckbox.setMargin(new Insets(0, 0, 0, 0));
  126. serverCheckbox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  127. dmdircCheckbox.setMargin(new Insets(0, 0, 0, 0));
  128. dmdircCheckbox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  129. setLayout(new MigLayout(
  130. "fill, wmin 600, wmax 600, hmin 400, hmax 400"));
  131. add(info, "span, growx, wrap, gapbottom unrel");
  132. add(new JLabel("Name: "), "aligny top, shrink");
  133. add(name, "growx, pushx, wrap");
  134. add(new JLabel("Email: "), "aligny top, shrink");
  135. add(email, "growx, pushx, wrap");
  136. add(new JLabel("Feedback: "), "aligny top, shrink");
  137. add(new JScrollPane(feedback), "grow, push, wrap");
  138. add(serverCheckbox, "skip 1, growx, wrap");
  139. add(dmdircCheckbox, "skip 1, growx, wrap");
  140. add(getCancelButton(), "skip, split 2, right, sg button");
  141. add(getOkButton(), "right, sg button");
  142. }
  143. /**
  144. * Lays out the components.
  145. *
  146. * @param error Did the submission error?
  147. */
  148. public void layoutComponents2(final StringBuilder error) {
  149. getContentPane().setVisible(false);
  150. getContentPane().removeAll();
  151. getOkButton().setEnabled(true);
  152. getOkButton().setText("Close");
  153. getOkButton().setActionCommand("Close");
  154. setLayout(new MigLayout(
  155. "fill, wmin 600, wmax 600, hmin 400, hmax 400"));
  156. info.setText(error.toString());
  157. add(info, "span 3, grow, push, wrap");
  158. add(getOkButton(), "skip, right, tag ok, sg button");
  159. getContentPane().setVisible(true);
  160. }
  161. /** Adds listeners to the components. */
  162. private void addListeners() {
  163. getOkButton().addActionListener(this);
  164. getCancelButton().addActionListener(this);
  165. feedback.getDocument().addDocumentListener(this);
  166. }
  167. /** Checks and sends the feedback. */
  168. private void send() {
  169. sentReport = true;
  170. getOkButton().setEnabled(false);
  171. getCancelButton().setEnabled(false);
  172. final StringBuilder serverInfo = new StringBuilder();
  173. final StringBuilder dmdircInfo = new StringBuilder();
  174. if (serverCheckbox.isSelected()) {
  175. for (Server server : serverManager.getServers()) {
  176. if (server.getState().isDisconnected()) {
  177. continue;
  178. }
  179. serverInfo.append("Server name: ").append(server.getName())
  180. .append("\n");
  181. serverInfo.append("Actual name: ").append(server.getParser()
  182. .getServerName()).append("\n");
  183. serverInfo.append("Network: ").append(server.getNetwork())
  184. .append("\n");
  185. serverInfo.append("IRCd: ").append(server.getParser()
  186. .getServerSoftware()).append(" - ");
  187. serverInfo.append(server.getParser().getServerSoftwareType())
  188. .append("\n");
  189. serverInfo.append("Modes: ").append(server.getParser()
  190. .getBooleanChannelModes()).append(" ");
  191. serverInfo.append(server.getParser().getListChannelModes())
  192. .append(" ");
  193. serverInfo.append(server.getParser().getParameterChannelModes())
  194. .append(" ");
  195. serverInfo.append(server.getParser().
  196. getDoubleParameterChannelModes());
  197. }
  198. }
  199. if (dmdircCheckbox.isSelected()) {
  200. dmdircInfo.append("DMDirc version: ").append(ClientInfo.getVersionInformation())
  201. .append("\n");
  202. dmdircInfo.append("Profile directory: ").append(configDirectory).append("\n");
  203. dmdircInfo.append("Java version: ").append(ClientInfo.getJavaInformation())
  204. .append("\n");
  205. dmdircInfo.append("OS Version: ").append(ClientInfo.getOperatingSystemInformation())
  206. .append("\n");
  207. dmdircInfo.append("Look & Feel: ").append(SwingController.getLookAndFeel());
  208. }
  209. new SendWorker(this, config, name.getText().trim(), email.getText().trim(),
  210. feedback.getText().trim(), serverInfo.toString().trim(),
  211. dmdircInfo.toString().trim()).executeInExecutor();
  212. }
  213. /** Validates the input. */
  214. private void validateInput() {
  215. if (feedback.getDocument().getLength() > 0) {
  216. getOkButton().setEnabled(true);
  217. } else {
  218. getOkButton().setEnabled(false);
  219. }
  220. }
  221. /**
  222. * {@inheritDoc}
  223. *
  224. * @param e action event
  225. */
  226. @Override
  227. public void actionPerformed(final ActionEvent e) {
  228. switch (e.getActionCommand()) {
  229. case "Send":
  230. if (!sentReport) {
  231. send();
  232. }
  233. break;
  234. case "Close":
  235. dispose();
  236. break;
  237. }
  238. }
  239. /**
  240. * {@inheritDoc}
  241. *
  242. * @param e Document event
  243. */
  244. @Override
  245. public void insertUpdate(final DocumentEvent e) {
  246. validateInput();
  247. }
  248. /**
  249. * {@inheritDoc}
  250. *
  251. * @param e Document event
  252. */
  253. @Override
  254. public void removeUpdate(final DocumentEvent e) {
  255. validateInput();
  256. }
  257. /** {@inheritDoc} */
  258. @Override
  259. public void changedUpdate(final DocumentEvent e) {
  260. // Do nothing
  261. }
  262. }