Line data Source code
1 : // Copyright (C) 2015 The Android Open Source Project
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : package com.google.gerrit.extensions.client;
16 :
17 : import java.util.List;
18 :
19 : /** Preferences about a single user. */
20 151 : public class GeneralPreferencesInfo {
21 :
22 : /** Default number of items to display per page. */
23 : public static final int DEFAULT_PAGESIZE = 25;
24 :
25 : /** Preferred method to download a change. */
26 149 : public enum DownloadCommand {
27 149 : PULL,
28 149 : CHECKOUT,
29 149 : CHERRY_PICK,
30 149 : FORMAT_PATCH,
31 149 : BRANCH,
32 149 : RESET,
33 : }
34 :
35 151 : public enum DateFormat {
36 : /** US style dates: Apr 27, Feb 14, 2010 */
37 151 : STD("MMM d", "MMM d, yyyy"),
38 :
39 : /** US style dates: 04/27, 02/14/10 */
40 151 : US("MM/dd", "MM/dd/yy"),
41 :
42 : /** ISO style dates: 2010-02-14 */
43 151 : ISO("MM-dd", "yyyy-MM-dd"),
44 :
45 : /** European style dates: 27. Apr, 27.04.2010 */
46 151 : EURO("d. MMM", "dd.MM.yyyy"),
47 :
48 : /** UK style dates: 27/04, 27/04/2010 */
49 151 : UK("dd/MM", "dd/MM/yyyy");
50 :
51 : private final String shortFormat;
52 : private final String longFormat;
53 :
54 151 : DateFormat(String shortFormat, String longFormat) {
55 151 : this.shortFormat = shortFormat;
56 151 : this.longFormat = longFormat;
57 151 : }
58 :
59 : public String getShortFormat() {
60 0 : return shortFormat;
61 : }
62 :
63 : public String getLongFormat() {
64 0 : return longFormat;
65 : }
66 : }
67 :
68 151 : public enum DiffView {
69 151 : SIDE_BY_SIDE,
70 151 : UNIFIED_DIFF
71 : }
72 :
73 151 : public enum EmailStrategy {
74 151 : ENABLED,
75 151 : CC_ON_OWN_COMMENTS,
76 151 : ATTENTION_SET_ONLY,
77 151 : DISABLED
78 : }
79 :
80 151 : public enum EmailFormat {
81 151 : PLAINTEXT,
82 151 : HTML_PLAINTEXT
83 : }
84 :
85 151 : public enum DefaultBase {
86 151 : AUTO_MERGE(null),
87 151 : FIRST_PARENT(-1);
88 :
89 : private final String base;
90 :
91 151 : DefaultBase(String base) {
92 151 : this.base = base;
93 151 : }
94 :
95 : DefaultBase(int base) {
96 151 : this(Integer.toString(base));
97 151 : }
98 :
99 : public String getBase() {
100 0 : return base;
101 : }
102 : }
103 :
104 151 : public enum Theme {
105 151 : AUTO,
106 151 : DARK,
107 151 : LIGHT
108 : }
109 :
110 151 : public enum TimeFormat {
111 : /** 12-hour clock: 1:15 am, 2:13 pm */
112 151 : HHMM_12("h:mm a"),
113 :
114 : /** 24-hour clock: 01:15, 14:13 */
115 151 : HHMM_24("HH:mm");
116 :
117 : private final String format;
118 :
119 151 : TimeFormat(String format) {
120 151 : this.format = format;
121 151 : }
122 :
123 : public String getFormat() {
124 0 : return format;
125 : }
126 : }
127 :
128 : /** Number of changes to show in a screen. */
129 : public Integer changesPerPage;
130 : /** Type of download URL the user prefers to use. */
131 : public String downloadScheme;
132 :
133 : public Theme theme;
134 : public DateFormat dateFormat;
135 : public TimeFormat timeFormat;
136 : public Boolean expandInlineDiffs;
137 : public Boolean highlightAssigneeInChangeTable;
138 : public Boolean relativeDateInChangeTable;
139 : public DiffView diffView;
140 : public Boolean sizeBarInChangeTable;
141 : public Boolean legacycidInChangeTable;
142 : public Boolean muteCommonPathPrefixes;
143 : public Boolean signedOffBy;
144 : public EmailStrategy emailStrategy;
145 : public EmailFormat emailFormat;
146 : public DefaultBase defaultBaseForMerges;
147 : public Boolean publishCommentsOnPush;
148 : public Boolean disableKeyboardShortcuts;
149 : public Boolean disableTokenHighlighting;
150 : public Boolean workInProgressByDefault;
151 : public List<MenuItem> my;
152 : public List<String> changeTable;
153 : public Boolean allowBrowserNotifications;
154 :
155 : public DateFormat getDateFormat() {
156 0 : if (dateFormat == null) {
157 0 : return DateFormat.STD;
158 : }
159 0 : return dateFormat;
160 : }
161 :
162 : public TimeFormat getTimeFormat() {
163 0 : if (timeFormat == null) {
164 0 : return TimeFormat.HHMM_12;
165 : }
166 0 : return timeFormat;
167 : }
168 :
169 : public DiffView getDiffView() {
170 0 : if (diffView == null) {
171 0 : return DiffView.SIDE_BY_SIDE;
172 : }
173 0 : return diffView;
174 : }
175 :
176 : public EmailStrategy getEmailStrategy() {
177 105 : if (emailStrategy == null) {
178 0 : return EmailStrategy.ENABLED;
179 : }
180 105 : return emailStrategy;
181 : }
182 :
183 : public EmailFormat getEmailFormat() {
184 54 : if (emailFormat == null) {
185 0 : return EmailFormat.HTML_PLAINTEXT;
186 : }
187 54 : return emailFormat;
188 : }
189 :
190 : public static GeneralPreferencesInfo defaults() {
191 151 : GeneralPreferencesInfo p = new GeneralPreferencesInfo();
192 151 : p.changesPerPage = DEFAULT_PAGESIZE;
193 151 : p.downloadScheme = null;
194 151 : p.theme = Theme.AUTO;
195 151 : p.dateFormat = DateFormat.STD;
196 151 : p.timeFormat = TimeFormat.HHMM_12;
197 151 : p.expandInlineDiffs = false;
198 151 : p.highlightAssigneeInChangeTable = true;
199 151 : p.relativeDateInChangeTable = false;
200 151 : p.diffView = DiffView.SIDE_BY_SIDE;
201 151 : p.sizeBarInChangeTable = true;
202 151 : p.legacycidInChangeTable = false;
203 151 : p.muteCommonPathPrefixes = true;
204 151 : p.signedOffBy = false;
205 151 : p.emailStrategy = EmailStrategy.ENABLED;
206 151 : p.emailFormat = EmailFormat.HTML_PLAINTEXT;
207 151 : p.defaultBaseForMerges = DefaultBase.FIRST_PARENT;
208 151 : p.publishCommentsOnPush = false;
209 151 : p.disableKeyboardShortcuts = false;
210 151 : p.disableTokenHighlighting = false;
211 151 : p.workInProgressByDefault = false;
212 151 : p.allowBrowserNotifications = true;
213 151 : return p;
214 : }
215 : }
|