Просмотр исходного кода

Improve formatting of whois events.

pull/618/head
Chris Smith 8 лет назад
Родитель
Сommit
bc37a9d982
2 измененных файлов: 34 добавлений и 15 удалений
  1. 2
    8
      res/com/dmdirc/ui/messages/format.yml
  2. 32
    7
      src/com/dmdirc/events/UserInfoResponseEvent.java

+ 2
- 8
res/com/dmdirc/ui/messages/format.yml Просмотреть файл

211
 UserInfoResponseEvent:
211
 UserInfoResponseEvent:
212
   before: "---------- User info for {{user.nickname}} ----------"
212
   before: "---------- User info for {{user.nickname}} ----------"
213
   after: "--------- End of info for {{user.nickname}} ---------"
213
   after: "--------- End of info for {{user.nickname}} ---------"
214
-  iterate: "entries"
215
-  format: "{{key}}: {{value}}"
214
+  iterate: "properties"
215
+  format: "{{friendlyName}}: {{rawValue}}"
216
   colour: 10
216
   colour: 10
217
 
217
 
218
 ################## TODO ############################################################################
218
 ################## TODO ############################################################################
237
 #  numeric_290=%4$s
237
 #  numeric_290=%4$s
238
 #  numeric_292=%4$s
238
 #  numeric_292=%4$s
239
 #  numeric_294=%4$s
239
 #  numeric_294=%4$s
240
-#  numeric_301=%4$s is away: %5$s
241
-#  numeric_311=-\n%4$s is %5$s@%6$s (%8$s).
242
-#  numeric_312=%4$s is connected to %5$s (%6$s).
243
-#  numeric_317=%4$s has been idle for %5$u; signed on at %6$TT on %6$TF.
244
-#  numeric_318=End of WHOIS info for %4$s.\n-
245
-#  numeric_319=%4$s is on: %5$s
246
 #  numeric_401=6A7000%4$s: %5$s
240
 #  numeric_401=6A7000%4$s: %5$s
247
 #  numeric_404=6A7000%5$s
241
 #  numeric_404=6A7000%5$s
248
 #  numeric_405=6A7000%4$s: %5$s
242
 #  numeric_405=6A7000%4$s: %5$s

+ 32
- 7
src/com/dmdirc/events/UserInfoResponseEvent.java Просмотреть файл

37
 public class UserInfoResponseEvent extends ServerDisplayableEvent {
37
 public class UserInfoResponseEvent extends ServerDisplayableEvent {
38
 
38
 
39
     private final User user;
39
     private final User user;
40
-    private final Map<UserInfoEvent.UserInfoType, String> info;
40
+    private final Map<UserInfoEvent.UserInfoType, UserInfoProperty> info;
41
 
41
 
42
     public UserInfoResponseEvent(final Connection connection, final long date,
42
     public UserInfoResponseEvent(final Connection connection, final long date,
43
             final User user, final Map<UserInfoEvent.UserInfoType, String> info) {
43
             final User user, final Map<UserInfoEvent.UserInfoType, String> info) {
44
         super(date, connection);
44
         super(date, connection);
45
         this.user = user;
45
         this.user = user;
46
-        this.info = new EnumMap<>(info);
46
+        this.info = new EnumMap<>(UserInfoEvent.UserInfoType.class);
47
+        info.forEach((key, value) -> this.info.put(key, new UserInfoProperty(key, value)));
47
     }
48
     }
48
 
49
 
49
     /**
50
     /**
63
      * @return An optional containing the information, if it was provided.
64
      * @return An optional containing the information, if it was provided.
64
      */
65
      */
65
     public Optional<String> getInfo(final UserInfoEvent.UserInfoType type) {
66
     public Optional<String> getInfo(final UserInfoEvent.UserInfoType type) {
66
-        return Optional.ofNullable(info.get(type));
67
+        return Optional.ofNullable(info.get(type)).map(UserInfoProperty::getRawValue);
67
     }
68
     }
68
 
69
 
69
     /**
70
     /**
70
-     * Gets a collection of all info entries in the response.
71
+     * Gets a collection of all info properties in the response.
71
      *
72
      *
72
-     * @return A collection of all user info entries.
73
+     * @return A collection of all user info properties.
73
      */
74
      */
74
-    public Collection<Map.Entry<UserInfoEvent.UserInfoType, String>> getEntries() {
75
-        return info.entrySet();
75
+    public Collection<UserInfoProperty> getProperties() {
76
+        return info.values();
77
+    }
78
+
79
+    public static class UserInfoProperty {
80
+
81
+        private final UserInfoEvent.UserInfoType type;
82
+        private final String rawValue;
83
+
84
+        public UserInfoProperty(final UserInfoEvent.UserInfoType type, final String rawValue) {
85
+            this.type = type;
86
+            this.rawValue = rawValue;
87
+        }
88
+
89
+        public UserInfoEvent.UserInfoType getType() {
90
+            return type;
91
+        }
92
+
93
+        public String getRawValue() {
94
+            return rawValue;
95
+        }
96
+
97
+        public String getFriendlyName() {
98
+            return type.name().charAt(0) + type.name().substring(1).toLowerCase().replace('_', ' ');
99
+        }
100
+
76
     }
101
     }
77
 
102
 
78
 }
103
 }

Загрузка…
Отмена
Сохранить