2 * This file is part of NixNote
\r
3 * Copyright 2009,2010 Randy Baumgarte
\r
4 * Copyright 2010 Hiroshi Miura
\r
6 * This file may be licensed under the terms of of the
\r
7 * GNU General Public License Version 2 (the ``GPL'').
\r
9 * Software distributed under the License is distributed
\r
10 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
11 * express or implied. See the GPL for the specific language
\r
12 * governing rights and limitations.
\r
14 * You should have received a copy of the GPL along with this
\r
15 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
16 * or write to the Free Software Foundation, Inc.,
\r
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 package cx.fbn.nevernote.filters;
\r
23 import com.evernote.edam.type.Note;
\r
24 import com.trolltech.qt.core.QCoreApplication;
\r
25 import com.trolltech.qt.core.QDateTime;
\r
27 public class DateAttributeFilterFactory {
\r
28 private DateAttributeFilterFactory () {};
\r
29 public enum FilterType {Today,Yesterday,ThisWeek,LastWeek,Month,LastMonth,Year,LastYear};
\r
31 public static DateAttributeFilter getFilter (FilterType fType, boolean since, boolean created) {
\r
34 return new checkToday(since,created);
\r
36 return new checkYesterday(since,created);
\r
38 return new checkThisWeek(since,created);
\r
40 return new checkLastWeek(since,created);
\r
42 return new checkMonth(since,created);
\r
44 return new checkLastMonth(since,created);
\r
46 return new checkYear(since,created);
\r
48 return new checkLastYear(since,created);
\r
50 throw new IllegalArgumentException("The filter type " + fType + " is not recognized.");
\r
54 class checkToday extends DateAttributeFilter {
\r
55 public checkToday(boolean since,boolean created) {
\r
56 super(since, created);
\r
58 // Check if it was within the last day
\r
60 public boolean attributeCheck(Note n) {
\r
61 QDateTime noteDate, current;
\r
62 noteDate = noteTime(n);
\r
63 current = currentTime();
\r
65 return noteDate.daysTo(current) == 0;
\r
67 return noteDate.daysTo(current) > 0;
\r
70 public String getLabel(){
\r
71 return QCoreApplication.translate("cx.fbn.nevernote.filters.DateAttributeFilter", "Today");
\r
75 class checkYesterday extends DateAttributeFilter {
\r
76 public checkYesterday(boolean since,boolean created) {
\r
77 super(since,created);
\r
80 // Check if it was within the last two days
\r
82 public boolean attributeCheck(Note n) {
\r
83 QDateTime noteDate, current;
\r
84 noteDate = noteTime(n);
\r
85 current = currentTime();
\r
87 return noteDate.daysTo(current) <= 1;
\r
89 return noteDate.daysTo(current) > 1;
\r
92 public String getLabel(){
\r
93 return QCoreApplication.translate("cx.fbn.nevernote.filters.DateAttributeFilter", "Yesterday");
\r
97 class checkThisWeek extends DateAttributeFilter {
\r
98 public checkThisWeek(boolean since,boolean created) {
\r
99 super(since,created);
\r
102 // Check if it was within the last two days
\r
104 public boolean attributeCheck(Note n) {
\r
105 QDateTime noteDate, current;
\r
106 noteDate = noteTime(n);
\r
107 current = currentTime();
\r
110 return noteDate.daysTo(current) <= 7;
\r
112 return noteDate.daysTo(current) > 7;
\r
115 public String getLabel(){
\r
116 return QCoreApplication.translate("cx.fbn.nevernote.filters.DateAttributeFilter", "This Week");
\r
120 class checkLastWeek extends DateAttributeFilter {
\r
121 public checkLastWeek(boolean since,boolean created) {
\r
122 super(since,created);
\r
125 // Check if it was within the last two weeks
\r
127 public boolean attributeCheck(Note n) {
\r
128 QDateTime noteDate, current;
\r
129 noteDate = noteTime(n);
\r
130 current = currentTime();
\r
133 return noteDate.daysTo(current) <= 14;
\r
135 return noteDate.daysTo(current) > 14;
\r
138 public String getLabel(){
\r
139 return QCoreApplication.translate("cx.fbn.nevernote.filters.DateAttributeFilter", "Last Week");
\r
143 class checkMonth extends DateAttributeFilter {
\r
144 public checkMonth(boolean since,boolean created) {
\r
145 super(since,created);
\r
148 // Check if it was within the last month
\r
150 public boolean attributeCheck(Note n) {
\r
151 QDateTime noteDate, current;
\r
152 noteDate = noteTime(n);
\r
153 current = currentTime();
\r
156 if (noteDate.date().year() == current.date().year())
\r
157 return noteDate.date().month() - current.date().month() == 0;
\r
161 if (noteDate.date().year() < current.date().year())
\r
164 return noteDate.date().month() - current.date().month() != 0;
\r
168 public String getLabel(){
\r
169 return QCoreApplication.translate("cx.fbn.nevernote.filters.DateAttributeFilter", "This Month");
\r
173 class checkLastMonth extends DateAttributeFilter {
\r
174 public checkLastMonth(boolean since,boolean created) {
\r
175 super(since,created);
\r
178 // Check if it was within the last two months
\r
180 public boolean attributeCheck(Note n) {
\r
181 QDateTime noteDate, current;
\r
182 noteDate = noteTime(n);
\r
183 current = currentTime();
\r
185 int ny = noteDate.date().year();
\r
186 int cy = current.date().year();
\r
187 int nm = noteDate.date().month();
\r
188 int cm = current.date().month();
\r
191 cm = cm+12*(cy-ny);
\r
202 public String getLabel(){
\r
203 return QCoreApplication.translate("cx.fbn.nevernote.filters.DateAttributeFilter", "Last Month");
\r
207 class checkYear extends DateAttributeFilter {
\r
208 public checkYear(boolean since,boolean created) {
\r
209 super(since,created);
\r
211 // Check if it was within this year
\r
213 public boolean attributeCheck(Note n) {
\r
214 QDateTime noteDate, current;
\r
215 noteDate = noteTime(n);
\r
216 current = currentTime();
\r
218 int ny = noteDate.date().year();
\r
219 int cy = current.date().year();
\r
227 public String getLabel(){
\r
228 return QCoreApplication.translate("cx.fbn.nevernote.filters.DateAttributeFilter", "This Year");
\r
232 class checkLastYear extends DateAttributeFilter {
\r
233 public checkLastYear(boolean since,boolean created) {
\r
234 super(since,created);
\r
237 // Check if it was within the last year
\r
239 public boolean attributeCheck(Note n) {
\r
240 QDateTime noteDate, current;
\r
241 noteDate = noteTime(n);
\r
242 current = currentTime();
\r
244 int ny = noteDate.date().year();
\r
245 int cy = current.date().year();
\r
253 public String getLabel(){
\r
254 return QCoreApplication.translate("cx.fbn.nevernote.filters.DateAttributeFilter", "Last Year");
\r